Upload
jatin-adroja
View
222
Download
0
Embed Size (px)
Citation preview
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 1/18
Vocational crash course on
“C with introduction to embedded C
• Course instructor :
Prof. Kumar Anand Singh
(Asst. Professor, EC, MEFGI)
• Course assistances:
Prof. Hetal Dave
(Asst. Professor, EC, MEFGI)
Mr. Saumil Vora
(Student, PG-VLSI, 1st year)
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 2/18
Time table chart
S.No. Topic Date Total Hours
TH (hrs.) PR(hrs.)
1. Introduction & Basic Structure 2 1
2. C Fundamentals 4 2
3. I/O Functions 2 1
4. Control statements 4 2
5. Arrays 4 2
6. String handling function 2 1
7. Functions 2 1
8. Structure & Unions 4 2
9. Pointers 4 2
10. Dynamic Memory Allocation 2 1
11. File handling 2 1
12. General Interview Questions 4 2
13. Introduction to Embedded C 4 2
TOTAL (12 days,10th Dec 2014 to 23rd Dec 2014) 40 20
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 3/18
CDesigned & WrittenBy
Dennis Ritchie
Reliable & Simple to useBasic Language
Procedural & StructuralProgramming
Used in Operating system&
Device driver programmin
Structure, Union &Exceptional handling are
Its characteristics
Faster & work in limitedmemory
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 4/18
Alphabets, Digits & Special Symbol
Constants, Variables & Keywords
Instructions
Writing Program
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 5/18
AlphabetsA to Z
a to z
Digits
0 to 9
Special Symbol All the other symbolsIn you keyboard
~ ` ! @ # $ % ^ & *( ) _ - + = { } [ ] \| ; ‘ : “ , . / < > ?
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 6/18
CConstants
Primary Secondary
• Integer• Real• Character
• Array• Pointer• Structure• Union• Enum
Variables
•
It is an entity which variesduring program execution.• It denotes the name of
memory location.• Types
• Integer•
Real• Character
• Particular type of variablecan hold same type ofconstants.
C Keywords
• Inbuilt variables with specificmeaning.
• Also known as “ReservedWords”
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 7/18
Must Have
One digit.The allowable range forinteger constants is -32768 to 32767.
Constant is an Entity that doesn’t changeInteger Constants
Must Not Have
decimal point.commas or blanks.
Must Have
One digit.Decimal PointThe allowable range forReal constants is 4 timesmore than Integer
Real/Floating Constants
Must Not Have
commas or blanks.
Must Have
Single character, digit or SymbolMaximum length is 1
Character Constants
Must Not Have
Multiple characterDecimal point
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 8/18
Words whose meaning has already been explained to the C compilerKeywords
Cannot be used as variable name.
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 9/18
Basic C Program
Content :
1. C Basic program with output & explanation
2. Steps to write C Program
3. Creation, Compilation & Execution
4. Basic Structure of C Program
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 10/18
Some Basic Commands :
S.No Command Explanation
1. #include <stdio.h>
This is a preprocessor command that
includes standard input output headerfile(stdio.h) from the C library beforecompiling a C program
2. int main()Main Modular function where execution ofany C Program begins
3. { Beginning of the main function
4. /* comments */ Wont be compiled by compiler
5.printf(“Hello_World!
“);Prints the information under “ “.
6. getch(); Waits for any character input from keyboard
7. return 0; It returns 0(Integer) to compiler
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 11/18
My First Program
#include <stdio.h>
int main()
{
/* Our first simple C basic program */
printf(“Hello World! “);
getch();
return 0;
}
This is a preprocessorcommand that includesstandard input outputheader file(stdio.h) from
the C library beforecompiling a C program
Main Modular Function
Wont be compiled
By compiler (hidden)
Prints the informationIn between “ “
Wait’s for theCharacter input
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 12/18
Create
Compile
Execute or Run
Get the output
And for Successful Compilation
Think & Write on Paper before Create
Perform Dry Run then Compile
Give proper inputs forgetting desired output
Execute or Run
Debug
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 13/18
Documentation section
Link Section
Definition Section
Global declaration
Function prototypedeclaration
Main function
User defined function
/* Author : Kumar Anand Singh */
#include <stdio.h> /* Link section */
int total = 0; /* Global declaration and definition section */
int sum (int, int); /* Function declaration section */
int main () /* Main function */
{
printf (“This is a C basic program \n”);total = sum (1, 1);printf (“Sum of two numbers : %d \n”, total);return 0;}
int sum (int a, int b) /* User defined function */ { /* definition section */
return a + b;
}
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 14/18
Mostly used Inbuilt Functions Under stdio.h
fprintf Formatted File Write
fscanf Formatted File Read
printf Formatted Write
scanf Formatted Read
fclose Close File
fopen Open File
remove Remove Filerename Rename File
getc Read Characters from File
getchar Read Character
gets Read String
putc Write Character to File
putchar Write Character
puts Write String
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 15/18
Mostly used Inbuilt Functions Under conio.h
Function Description
clrscr() This function is used to clear the output screen.
getch() It reads character from keyboard
getche()It reads character from keyboard and echoes to o/p
screen
textcolor() This function is used to change the text color
textbackground()
This function is used to change text background
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 16/18
Don’t use any functionBefore any initialization
Size of memory isallocated at Run Time
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 17/18
/* Program to Get “String, Integer Character” using printf() &Scanf() function under stdio.h */
#include<stdio.h>#include<conio.h>
int main()
{
int i;
char ch1,ch2;
char str1[20],str2[20];
clrscr();
printf(“Enter String Integer & character\t “);
scanf(“%s %d %c ”,str1,&i,&ch1);
getch();
return(0);
}
Int is a data type which stores 2 byte of Data1 = 28, 2 = 216 = 65536 ⇒ −32768 ≤ ≤ 32767
Char is a data type which stores 1 byte of Data
Stores 19 different characters where 20th character is NULL ɸ
&(ampersand) represent address of variableString self represent address so it doesn’t requiresthis assignment. str==&str[0]
7/23/2019 Chapter 1_Introdction & Structure
http://slidepdf.com/reader/full/chapter-1introdction-structure 18/18