SlideShare ist ein Scribd-Unternehmen logo
1 von 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]

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Kürzlich hochgeladen (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.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]