SlideShare une entreprise Scribd logo
1  sur  3
MCA DEPARTMENT | C Basics
C
1
History & Evolution:
B
BCPL
C - with Unix 1962- Dennis Ritchie
At: AT &T BELL Labs,US.
Designed for systems programming:
• Operating systems
• Utility programs
• Compilers
• Filters
Characteristics:
 Currently, the most commonly-
used language for embedded
systems
 “High-level assembly”
 Very portable: compilers exist for
virtually every processor
 Easy-to-understand compilation
 Produces efficient code
 Fairly concise
Structure of C Program:
(1) Preprocessor Commands
(2) Functions
(3) Variables
(4) Statements & Expressions
(5) Comments
Example:
#include <stdio.h>-------------(1)
int main()---------------------(2)
{
/* my first program in C */--(5)
int a;-------------------------(3)
printf("Hello, World! n");----(4)
return 0;
}
Compilation & Execution:
(1) Press F2- to Save
(2) Press F9 – Compilation
(3) Press Ctrl+F9 - Execution
Tokens in C:
1) Keyword
2) Identifier
3) Constant
4) Comments
5) Symbol
1) Keywords
auto else long switch
break
enum register
typedef
case
extern
return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double
2) Identifier
 A name used to identify a variable,
function, or any other user-defined
item.
 An identifier starts with a letter A
to Z or a to z or an underscore _
followed by zero or more letters,
underscores, and digits (0 to 9).
 C does not allow punctuation
characters such as @, $, and %
within identifiers.
 C is a case sensitive programming
language.
3) Constant
The constants refer to fixed values
that the program may not alter
during its execution. These fixed
values are also called literals.
1. Using #define preprocessor.
2. Using const keyword.
1. The #define Preprocessor
#define identifier value
// example for preprocessor
#include <stdio.h>
#define LENGTH 10
#define WIDTH 5
#define NEWLINE 'n'
int main()
{
int area;
area = LENGTH * WIDTH;
printf("value of area : %d", area);
printf("%c", NEWLINE);
return 0;
}
Output:
value of area : 50
2.The const Keyword
Use const prefix to declare constants
with a specific type as follows:
const type variable = value;
// Example for Const keyword
#include <stdio.h>
int main()
{
const int LENGTH = 10;
const int WIDTH = 5;
const char NEWLINE = 'n';
int area;
area = LENGTH * WIDTH;
printf("value of area : %d", area);
printf("%c", NEWLINE);
return 0;
}
Output:
value of area : 50
4) Comments
Single line comment - //
Multiline Comment - /* --*/
5) Symbol
Punctuators - : , , ;.
Escape sequences
Escape
sequence
Meaning
  character
' ' character
" " character
? ? character
a Alert orbell
b Backspace
f Form feed
n Newline
r Carriage return
t Horizontal tab
v Vertical tab
ooo Octal number ofone to three digits
xhh . . . Hexadecimal number of oneor more digits
Input output function:
Built-in functions to read given input and
write data on screen, printer or in any file.
scanf()and printf()functions
// Demo of printf,scanf
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
printf("Enter a value");
scanf("%d",&i);
printf( "nYou entered: %d",i);
getch();
}
getchar() & putchar() functions
// Demo of getchar, putchar
#include <stdio.h>
#include <conio.h>
void main( )
{
int c;
printf("Enter a character");
C PROGRAMMING - BASICS
MCA DEPARTMENT | C Basics
C
2
c=getchar();
putchar(c);
getch();
}
gets() & puts() functions
// Demo of gets(), puts()
#include<stdio.h>
#include<conio.h>
void main()
{
char str[100];
printf("Enter a string");
gets( str );
puts( str );
getch();
}
Somebasicsyntaxrule forC program
 C is a case sensitive language so all C
instructions must be written in lower case
letter.
 All C statement must be end with a
semicolon.
 Whitespace is used in C to describe
blanks and tabs.
 Whitespace is required between
keywords and identifiers
Data Types
 A data type is
o A set of values AND
o A set of operations on those values

 A data type is used to
o Identify the type of a variable when
the variable is declared
o Identify the type of the return value of
a function
o Identify the type of a parameter
expected by a function
The type of a variable determines how
much space it occupies in storage and how
the bit pattern stored is interpreted.
 All data types are transformed into a
uniform representation
 They are stored in a computer and
transformed back to their original
form when retrieved.
This universal representation is called a
bit.
Binary Digit
• pattern or a sequence of 0s and
1s.
Objective of Data Type:
• Is to process data
• Data is classified into specific
types
 Numerical
 Alphabetical
 Audio
 Video
Two Classifications of Data Types
• Built-in data types
(1) Fundamental data types
void – used to denote the type with no
values
int – used to denote an integer type
char – used to denote a character type
float, double – used to denote a floating
point type
int *, float *, char * – used to denote a
pointer type, which is a
memory address type
(2) Derived data types
Array – a finite sequence (or table) of
variables of the same data type
String – an array of character variables
Structure – a collection of related
variables of the same and/or different data
types. The structure is called a record and
the variables in the record are called
members or fields
• Programmer-defined data types
– Structure
– Union
– Enumeration
(!) Fundamental data types
int - data type
int is used to define integer numbers.
{
int Count;
Count = 5;
}
float - data type
float is used to define floating point
numbers.
{
float Miles;
Miles = 5.6;
}
double - data type
double is used to define BIG floating point
numbers. It reserves twice the storage for
the number. On PCs this is likely to be 8
bytes.
{
double Atoms;
Atoms = 2500000;
}
char - data type
char defines characters.
{
char Letter;
Letter = 'x';
}
MCA DEPARTMENT | C Basics
C
3
Modifiers
The data types explained above have the
following modifiers.
 short
 long
 signed
 unsigned
The modifiers define the amount of storage
allocated to the variable. The amount of
storage allocated is not cast in stone. ANSI
has the following rules:
short int <= int <= long int
float <= double <= long double
S.No C Data types
storage
Size
Range
1 char 1 –127 to 127
2 int 2 –32,767 to 32,767
3 float 4
1E–37 to 1E+37 withsix
digits of precision
4 double 8
1E–37 to 1E+37 withten
digits of precision
5 long double 10
1E–37 to 1E+37 withten
digits of precision
6 long int 4
–2,147,483,647 to
2,147,483,647
7 short int 2 –32,767 to 32,767
8
unsigned
short int
2 0 to 65,535
9
signed
short int
2 –32,767 to 32,767
10
long long
int
8
–(2power(63) –1)to
2(power)63 –1
11
signed long
int
4
–2,147,483,647 to
2,147,483,647
12
unsigned
long int
4 0 to 4,294,967,295
13
unsigned
long long
int
8 2(power)64 –1
Example to check size of memory taken
by various datatypes.
#include<stdio.h>
int main()
{
printf("sizeof(char) == %dn",
sizeof(char));
printf("sizeof(short) == %dn",
sizeof(short));
printf("sizeof(int) == %dn",
sizeof(int));
printf("sizeof(long) == %dn",
sizeof(long));
printf("sizeof(float) == %dn",
sizeof(float));
printf("sizeof(double) == %dn",
sizeof(double));
printf("sizeof(long double) ==
%dn", sizeof(long double));
printf("sizeof(long long) ==
%dn", sizeof(long long));
return 0;
}
Declarations
The C language is a statically typed
language.
Ex:
#include <stdio.h>
int main() {
double a = 123.456;
double b = 50.2;
double c = 100.0;
double d[]= {a, b, c};
printf("a=%.3f,b=%.3f,c=%.3f,
d=[%.3f, %.3f, %.3f]n",
a, b, c, d[0], d[1], d[2]);
return 0;
}
Output:
a=123.456, b=50.200, c=100.000,
d=[123.456, 50.200, 100.000]

Contenu connexe

Tendances

Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generationIffat Anjum
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)bolovv
 
Tutorial on c language programming
Tutorial on c language programmingTutorial on c language programming
Tutorial on c language programmingSudheer Kiran
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Dushmanta Nath
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationRamchandraRegmi
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]MomenMostafa
 
Code generator
Code generatorCode generator
Code generatorTech_MX
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Dushmanta Nath
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic Manzoor ALam
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationAkshaya Arunan
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c languageRavindraSalunke3
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming LanguageSteve Johnson
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 

Tendances (20)

Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
Tutorial on c language programming
Tutorial on c language programmingTutorial on c language programming
Tutorial on c language programming
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
C++
C++C++
C++
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
 
Code generator
Code generatorCode generator
Code generator
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c language
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Ch8a
Ch8aCh8a
Ch8a
 

En vedette

Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
Classic hits radio show script
Classic hits radio show scriptClassic hits radio show script
Classic hits radio show scriptdargo94
 
Final Radio Show Script
Final Radio Show ScriptFinal Radio Show Script
Final Radio Show ScriptKathleenae
 
Radio Broadcasting and Scriptwriting
Radio Broadcasting and ScriptwritingRadio Broadcasting and Scriptwriting
Radio Broadcasting and Scriptwritingjessica_jessica
 
Writing a radio script
Writing a radio scriptWriting a radio script
Writing a radio scriptDavid Brewer
 
Tv news script formats & sample scripts
Tv news script formats & sample scriptsTv news script formats & sample scripts
Tv news script formats & sample scriptsJun Tariman
 
FM Radio Program Script
FM Radio Program ScriptFM Radio Program Script
FM Radio Program ScriptRoxanne Robes
 
Example radio script
Example radio scriptExample radio script
Example radio scriptISM
 
Radio Script writing and Broadcasting
Radio Script writing and BroadcastingRadio Script writing and Broadcasting
Radio Script writing and BroadcastingMary Queen Bernardo
 

En vedette (12)

Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
 
Classic hits radio show script
Classic hits radio show scriptClassic hits radio show script
Classic hits radio show script
 
Radio Scripts
Radio ScriptsRadio Scripts
Radio Scripts
 
Final Radio Show Script
Final Radio Show ScriptFinal Radio Show Script
Final Radio Show Script
 
Radio Broadcasting and Scriptwriting
Radio Broadcasting and ScriptwritingRadio Broadcasting and Scriptwriting
Radio Broadcasting and Scriptwriting
 
Writing a radio script
Writing a radio scriptWriting a radio script
Writing a radio script
 
Talk show example and structure
Talk show example and structureTalk show example and structure
Talk show example and structure
 
Tv news script formats & sample scripts
Tv news script formats & sample scriptsTv news script formats & sample scripts
Tv news script formats & sample scripts
 
FM Radio Program Script
FM Radio Program ScriptFM Radio Program Script
FM Radio Program Script
 
Example radio script
Example radio scriptExample radio script
Example radio script
 
Radio Script writing and Broadcasting
Radio Script writing and BroadcastingRadio Script writing and Broadcasting
Radio Script writing and Broadcasting
 

Similaire à Theory1&amp;2

Introduction to c
Introduction to cIntroduction to c
Introduction to camol_chavan
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxLECO9
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxSKUP1
 

Similaire à Theory1&amp;2 (20)

Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Clanguage
ClanguageClanguage
Clanguage
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
C tutorial
C tutorialC tutorial
C tutorial
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
C
CC
C
 
C language
C languageC language
C language
 
C language
C languageC language
C language
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
 
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptxDATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
 
dinoC_ppt.pptx
dinoC_ppt.pptxdinoC_ppt.pptx
dinoC_ppt.pptx
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part2
C programming part2C programming part2
C programming part2
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 

Plus de Dr.M.Karthika parthasarathy

IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...Dr.M.Karthika parthasarathy
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxDr.M.Karthika parthasarathy
 

Plus de Dr.M.Karthika parthasarathy (20)

IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
 
Linux Lab Manual.doc
Linux Lab Manual.docLinux Lab Manual.doc
Linux Lab Manual.doc
 
Unit 2 IoT.pdf
Unit 2 IoT.pdfUnit 2 IoT.pdf
Unit 2 IoT.pdf
 
Unit 3 IOT.docx
Unit 3 IOT.docxUnit 3 IOT.docx
Unit 3 IOT.docx
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptx
 
Unit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docxUnit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docx
 
Introduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptxIntroduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptx
 
IoT Unit 2.pdf
IoT Unit 2.pdfIoT Unit 2.pdf
IoT Unit 2.pdf
 
Chapter 3 heuristic search techniques
Chapter 3 heuristic search techniquesChapter 3 heuristic search techniques
Chapter 3 heuristic search techniques
 
Ai mcq chapter 2
Ai mcq chapter 2Ai mcq chapter 2
Ai mcq chapter 2
 
Introduction to IoT unit II
Introduction to IoT  unit IIIntroduction to IoT  unit II
Introduction to IoT unit II
 
Introduction to IoT - Unit I
Introduction to IoT - Unit IIntroduction to IoT - Unit I
Introduction to IoT - Unit I
 
Internet of things Unit 1 one word
Internet of things Unit 1 one wordInternet of things Unit 1 one word
Internet of things Unit 1 one word
 
Unit 1 q&amp;a
Unit  1 q&amp;aUnit  1 q&amp;a
Unit 1 q&amp;a
 
Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1
 
Examples in OS synchronization for UG
Examples in OS synchronization for UG Examples in OS synchronization for UG
Examples in OS synchronization for UG
 
Process Synchronization - Monitors
Process Synchronization - MonitorsProcess Synchronization - Monitors
Process Synchronization - Monitors
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
.net progrmming part3
.net progrmming part3.net progrmming part3
.net progrmming part3
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 

Dernier

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 

Dernier (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

Theory1&amp;2

  • 1. MCA DEPARTMENT | C Basics C 1 History & Evolution: B BCPL C - with Unix 1962- Dennis Ritchie At: AT &T BELL Labs,US. Designed for systems programming: • Operating systems • Utility programs • Compilers • Filters Characteristics:  Currently, the most commonly- used language for embedded systems  “High-level assembly”  Very portable: compilers exist for virtually every processor  Easy-to-understand compilation  Produces efficient code  Fairly concise Structure of C Program: (1) Preprocessor Commands (2) Functions (3) Variables (4) Statements & Expressions (5) Comments Example: #include <stdio.h>-------------(1) int main()---------------------(2) { /* my first program in C */--(5) int a;-------------------------(3) printf("Hello, World! n");----(4) return 0; } Compilation & Execution: (1) Press F2- to Save (2) Press F9 – Compilation (3) Press Ctrl+F9 - Execution Tokens in C: 1) Keyword 2) Identifier 3) Constant 4) Comments 5) Symbol 1) Keywords auto else long switch break enum register typedef case extern return union char float short unsigned const for signed void continue goto sizeof volatile default if static while do int struct _Packed double 2) Identifier  A name used to identify a variable, function, or any other user-defined item.  An identifier starts with a letter A to Z or a to z or an underscore _ followed by zero or more letters, underscores, and digits (0 to 9).  C does not allow punctuation characters such as @, $, and % within identifiers.  C is a case sensitive programming language. 3) Constant The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. 1. Using #define preprocessor. 2. Using const keyword. 1. The #define Preprocessor #define identifier value // example for preprocessor #include <stdio.h> #define LENGTH 10 #define WIDTH 5 #define NEWLINE 'n' int main() { int area; area = LENGTH * WIDTH; printf("value of area : %d", area); printf("%c", NEWLINE); return 0; } Output: value of area : 50 2.The const Keyword Use const prefix to declare constants with a specific type as follows: const type variable = value; // Example for Const keyword #include <stdio.h> int main() { const int LENGTH = 10; const int WIDTH = 5; const char NEWLINE = 'n'; int area; area = LENGTH * WIDTH; printf("value of area : %d", area); printf("%c", NEWLINE); return 0; } Output: value of area : 50 4) Comments Single line comment - // Multiline Comment - /* --*/ 5) Symbol Punctuators - : , , ;. Escape sequences Escape sequence Meaning character ' ' character " " character ? ? character a Alert orbell b Backspace f Form feed n Newline r Carriage return t Horizontal tab v Vertical tab ooo Octal number ofone to three digits xhh . . . Hexadecimal number of oneor more digits Input output function: Built-in functions to read given input and write data on screen, printer or in any file. scanf()and printf()functions // Demo of printf,scanf #include<stdio.h> #include<conio.h> void main() { int i; printf("Enter a value"); scanf("%d",&i); printf( "nYou entered: %d",i); getch(); } getchar() & putchar() functions // Demo of getchar, putchar #include <stdio.h> #include <conio.h> void main( ) { int c; printf("Enter a character"); C PROGRAMMING - BASICS
  • 2. MCA DEPARTMENT | C Basics C 2 c=getchar(); putchar(c); getch(); } gets() & puts() functions // Demo of gets(), puts() #include<stdio.h> #include<conio.h> void main() { char str[100]; printf("Enter a string"); gets( str ); puts( str ); getch(); } Somebasicsyntaxrule forC program  C is a case sensitive language so all C instructions must be written in lower case letter.  All C statement must be end with a semicolon.  Whitespace is used in C to describe blanks and tabs.  Whitespace is required between keywords and identifiers Data Types  A data type is o A set of values AND o A set of operations on those values   A data type is used to o Identify the type of a variable when the variable is declared o Identify the type of the return value of a function o Identify the type of a parameter expected by a function The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.  All data types are transformed into a uniform representation  They are stored in a computer and transformed back to their original form when retrieved. This universal representation is called a bit. Binary Digit • pattern or a sequence of 0s and 1s. Objective of Data Type: • Is to process data • Data is classified into specific types  Numerical  Alphabetical  Audio  Video Two Classifications of Data Types • Built-in data types (1) Fundamental data types void – used to denote the type with no values int – used to denote an integer type char – used to denote a character type float, double – used to denote a floating point type int *, float *, char * – used to denote a pointer type, which is a memory address type (2) Derived data types Array – a finite sequence (or table) of variables of the same data type String – an array of character variables Structure – a collection of related variables of the same and/or different data types. The structure is called a record and the variables in the record are called members or fields • Programmer-defined data types – Structure – Union – Enumeration (!) Fundamental data types int - data type int is used to define integer numbers. { int Count; Count = 5; } float - data type float is used to define floating point numbers. { float Miles; Miles = 5.6; } double - data type double is used to define BIG floating point numbers. It reserves twice the storage for the number. On PCs this is likely to be 8 bytes. { double Atoms; Atoms = 2500000; } char - data type char defines characters. { char Letter; Letter = 'x'; }
  • 3. MCA DEPARTMENT | C Basics C 3 Modifiers The data types explained above have the following modifiers.  short  long  signed  unsigned The modifiers define the amount of storage allocated to the variable. The amount of storage allocated is not cast in stone. ANSI has the following rules: short int <= int <= long int float <= double <= long double S.No C Data types storage Size Range 1 char 1 –127 to 127 2 int 2 –32,767 to 32,767 3 float 4 1E–37 to 1E+37 withsix digits of precision 4 double 8 1E–37 to 1E+37 withten digits of precision 5 long double 10 1E–37 to 1E+37 withten digits of precision 6 long int 4 –2,147,483,647 to 2,147,483,647 7 short int 2 –32,767 to 32,767 8 unsigned short int 2 0 to 65,535 9 signed short int 2 –32,767 to 32,767 10 long long int 8 –(2power(63) –1)to 2(power)63 –1 11 signed long int 4 –2,147,483,647 to 2,147,483,647 12 unsigned long int 4 0 to 4,294,967,295 13 unsigned long long int 8 2(power)64 –1 Example to check size of memory taken by various datatypes. #include<stdio.h> int main() { printf("sizeof(char) == %dn", sizeof(char)); printf("sizeof(short) == %dn", sizeof(short)); printf("sizeof(int) == %dn", sizeof(int)); printf("sizeof(long) == %dn", sizeof(long)); printf("sizeof(float) == %dn", sizeof(float)); printf("sizeof(double) == %dn", sizeof(double)); printf("sizeof(long double) == %dn", sizeof(long double)); printf("sizeof(long long) == %dn", sizeof(long long)); return 0; } Declarations The C language is a statically typed language. Ex: #include <stdio.h> int main() { double a = 123.456; double b = 50.2; double c = 100.0; double d[]= {a, b, c}; printf("a=%.3f,b=%.3f,c=%.3f, d=[%.3f, %.3f, %.3f]n", a, b, c, d[0], d[1], d[2]); return 0; } Output: a=123.456, b=50.200, c=100.000, d=[123.456, 50.200, 100.000]