SlideShare a Scribd company logo
1 of 64
• 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
• Developed between 1969 and 1973 along
with Unix
• Due mostly to Dennis Ritchie
• Designed for systems programming
– Operating systems
– Utility programs
– Compilers
– Filters
• Evolved from B, which evolved from BCPL
#include<stdio.h>
int main()
{
--other statements
}
• The files that are specified in the include
section is called as header file
• These are precompiled files that has some
functions defined in them
• We can call those functions in our program
by supplying parameters
• Header file is given an extension .h
• C Source file is given an extension .c
• This is the entry point of a program
• When a file is executed, the start point is the
main function
• From main function the flow goes as per the
programmers choice.
• There may or may not be other functions
written by user in a program
• Main function is compulsory for any c
program
#include<stdio.h>
int main()
{
printf(“Hello”);
return 0;
}
• This program prints Hello on the screen
when we execute it
• Type a program
• Save it
• Compile the program – This will generate an
exe file (executable)
• Run the program (Actually the exe created out
of compilation will run and not the .c file)
• In different compiler we have different option
for compiling and running. We give only the
concepts.
• Single line comment
– // (double slash)
– Termination of comment is by pressing enter
key
• Multi line comment
/*….
…….*/
This can span over to multiple lines
• arithmetic: + – * / %
• comparison: == != < <= > >=
• bitwise logical: & | ^ ~
• shifting: << >>
• lazy logical: && || !
• conditional: ? :
• assignment: = += -=
• increment/decrement: ++ --
• sequencing: ,
• pointer: * -> & []
• and: &
• or: |
• xor: ^
• not: ~
• left shift: <<
• right shift: >>
• Useful for bit-field manipulations
#define MASK 0x040
if (a & MASK) { … } /* Check bits */
c |= MASK; /* Set bits */
c &= ~MASK; /* Clear bits */
d = (a & MASK) >> 4; /* Select field */
• Syntax:
condition ? result1 : result2
If the condition is true, result1 is returned
else result2 is returned.
• 10==5 ? 11: 12
10!=5 ? 4 : 3
12>8 ? a : b
• A data type defines a collection of data
objects and a set of predefined operations
on those objects.
• Variables are data that will keep on changing
• Declaration
<<Data type>> <<variable name>>;
int a;
• Definition
<<varname>>=<<value>>;
a=10;
• Usage
<<varname>>
a=a+1; //increments the value of a by 1
• Should not be a reserved word like int etc..
• Should start with a letter or an
underscore(_)
• Can contain letters, numbers or underscore.
• No other special characters are allowed
including space
• Variable names are case sensitive
– A and a are different.
• char ch;
• int i;
• i = ‘a’; /* i is now 97 */
• ch = 65; /* ch is now ‘A’ */
• ch = ch + 1; /* ch is now ‘B’ */
• ch++; /* ch is now ‘C’ */
• if(‘a’ <= ch && ch <= ‘z’)
• for(ch = ‘A’; ch <= ‘Z’; ch++)
• The syntax of for loop is
for(initialisation;condition checking;increment)
{
set of statements
}
Eg: Program to print Hello 10 times
for(I=0;I<10;I++)
{
printf(“Hello”);
}
• The syntax of do while loop
do
{
set of statements
}while(condn);
Eg:
i=10; Output:
do 10987654321
{
printf(“%d”,i);
i--;
}while(i!=0)
if (condition)
{
stmt 1; //Executes if Condition is true
}
else
{
stmt 2; //Executes if condition is false
}
switch(var)
{
case 1: //if var=1 this case executes
stmt;
break;
case 2: //if var=2 this case executes
stmt;
break;
default: //if var is something else this will execute
stmt;
}
• When the break statement is executed
inside a loop-statement, the loop-statement
is terminated immediately
• The execution of the program will continue
with the statement following the loop-
statement
• Syntax :
break;
•When the continue statement is executed
inside a loop-statement, the program will
skip over the remainder of the loop-body
to the end of the loop.
•Syntax
Continue;
• Array
– Group of consecutive memory locations
– Same name and type
• To refer to an element, specify
– Array name
– Position number
• Format:
arrayname[ position number ]
– First element at position 0
– n element array named c:
• c[ 0 ], c[ 1 ]...c[ n – 1 ]
• When declaring arrays, specify
– Name
– Type of array
– Number of elements
arrayType arrayName[ numberOfElements ];
– Examples:
int c[ 10 ];
float myArray[ 3284 ];
• Declaring multiple arrays of same type
– Format similar to regular variables
– Example:
int b[ 100 ], x[ 27 ];
• Initializers
int n[ 5 ] = { 1, 2, 3, 4, 5 };
– If not enough initializers, rightmost elements
become 0
int n[ 5 ] = { 0 }
• All elements 0
– If too many a syntax error is produced syntax error
– C arrays have no bounds checking
• If size omitted, initializers determine it
int n[ ] = { 1, 2, 3, 4, 5 };
– 5 initializers, therefore 5 element array
• Initialization
– int b[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };
– Initializers grouped by row in braces
– If not enough, unspecified elements set to zero
int b[ 2 ][ 2 ] = { { 1 }, { 3, 4 } };
• Referencing elements
– Specify row, then column
printf( "%d", b[ 0 ][ 1 ] );
1 2
3 4
1 0
3 4
So far we have used one-dimensional (1D) arrays,
but we can also use arrays with 2 or more
dimensions. 2D arrays essentially correspond to
matrices.
Example:
• int A; // single variable
• int B[6]; // 1D array
• int C[3][4]; // 2D array (matrix)
• int D[3][4][5]; // 3D array
• int E[3][4][5][3]; // 4D array
• //etc
• A string is a sequence of characters treated
as a group
• array can be of any length
• end of string is indicated by a delimiter, the
zero character ‘0’
"A String" A 0gnirtS
• String literal values are represented by sequences
of characters between double quotes (“)
• Examples
– “” - empty string
– “hello”
• “a” versus ‘a’
– ‘a’ is a single character value (stored in 1 byte) as the
ASCII value for a
– “a” is an array with two characters, the first is a, the
second is the character value 0
• Allocate an array of a size large enough to hold the
string (plus 1 extra value for the delimiter)
• Examples (with initialization):
char str1[6] = “Hello”;
char str2[] = “Hello”;
char *str3 = “Hello”;
char str4[6] = {‘H’,’e’,’l’,’l’,’o’,’0’};
• C provides a wide range of string functions for
performing different string tasks
• Examples
– strlen(str) – To find length of string str
– strrev(str) – Reverses the string str as rts
– strcat(str1,str2) – Appends str2 to str1 and returns str1
– strcpy(st1,st2) – copies the content of st2 to st1
– strcmp(s1,s2) – Compares the two string s1 and s2
– strcmpi(s1,s2) – Case insensitive comparison of strings
• Functions come from the utility library string.h
– #include <string.h> to use
• A pointer is a variable whose value is the
address of another variable, i.e., direct
address of the memory location. Like any
variable or constant, you must declare a
pointer before you can use it to store any
variable address. The general form of a
pointer variable declaration is:
• type *var-name;
• There are few important operations, which we
will do with the help of pointers very
frequently.
• we define a pointer variable
• assign the address of a variable to a pointer
• finally access the value at the address
available in the pointer variable. This is done
by using unary operator * that returns the
value of the variable located at the address
specified by its operand. Following example
makes use of these operations:
• Functions
– Modularize a program
– All variables declared inside functions are local variables
• Known only in function defined
– Parameters
• Communicate information between functions
• Local variables
• Benefits of functions
– Divide and conquer
• Manageable program development
– Software reusability
• Use existing functions as building blocks for new programs
• Abstraction - hide internal details (library functions)
– Avoid code repetition
• Function definition format
return-value-type function-name( parameter-list )
{
declarations and statements
}
– Function-name: any valid identifier
– Return-value-type: data type of the result (default
int)
• void – indicates that the function returns nothing
– Parameter-list: comma separated list, declares
parameters
• A type must be listed explicitly for each parameter unless,
the parameter is of type int
• Function definition format (continued)
return-value-type function-name( parameter-list )
{
declarations and statements
}
– Declarations and statements: function body (block)
• Variables can be declared inside blocks (can be nested)
• Functions can not be defined inside other functions
– Returning control
• If nothing returned
– return;
– or, until reaches right brace
• If something returned
– return expression;
• Call by value
– Copy of argument passed to function
– Changes in function do not effect original
– Use when function does not need to modify
argument
• Avoids accidental changes
• Call by reference
– Passes original argument
– Changes in function effect original
– Only used with trusted functions
• Recursive functions
– Functions that call themselves
– Can only solve a base case
– Divide a problem up into
• What it can do
• What it cannot do
– What it cannot do resembles original problem
– The function launches a new copy of itself (recursion step) to
solve what it cannot do
– Eventually base case gets solved
• Gets plugged in, works its way up and solves whole
problem
• Example: factorials
– 5! = 5 * 4 * 3 * 2 * 1
– Notice that
• 5! = 5 * 4!
• 4! = 4 * 3! ...
– Can compute factorials recursively
– Solve base case (1! = 0! = 1) then plug in
• 2! = 2 * 1! = 2 * 1 = 2;
• 3! = 3 * 2! = 3 * 2 = 6;
• A structure is a collection of variables under
a single name. These variables can be of
different types, and each has a name which
is used to select it from the structure. A
structure is a convenient way of grouping
several pieces of related information
together.
• Structures are user defined data types
• It is a collection of heterogeneous data
• It can have integer, float, double or character
data in it
• We can also have array of structures
struct <<structname>>
{
members;
}element;
We can access element.members;
•Compound data:
•A date is
– an int month and
– an int day and
– an int year
• The typedef operator is used for creating
alias of a data type
• For example I have this statement
typedef int integer;
Now I can use integer in place of int
i.e instead of declaring int a;, I can use
integer a;
This is applied for structures too.
• typedef struct student
• {
• int id;
• Char name[10];
• }s;
• Now I can put
• s s1,s2;
• A union value doesn’t “know” which case it
contains
•Choices:
•An element is
– an int i or
– a char c
union AnElt {
int i;
char c;
} elt1, elt2;
elt1.i = 4;
elt2.c = ’a’;
elt2.i = 0xDEADBEEF;
if (elt1 currently has a char) …
Symbolic constants
#define PI 3.1415926535
Macros with arguments for emulating inlining
#define min(x,y) ((x) < (y) ? (x) :
(y))
Conditional compilation
#ifdef __STDC__
File inclusion for sharing of declarations
#include “myheaders.h”
Header file dependencies usually form a directed acyclic
graph (DAG)
How do you avoid defining things twice?
Convention: surround each header (.h) file with a
conditional:
#ifndef __MYHEADER_H__
#define __MYHEADER_H__
/* Declarations */
#endif
C language

More Related Content

What's hot

Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisEelco Visser
 
Introduction of flex
Introduction of flexIntroduction of flex
Introduction of flexvip_du
 
Hardware Description Language
Hardware Description Language Hardware Description Language
Hardware Description Language Prachi Pandey
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)Sami Said
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesEelco Visser
 
Digital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language VerilogDigital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language VerilogAbhiraj Bohra
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming LanguageSteve Johnson
 
An Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprAn Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprPrabhavathi P
 
Compiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor ServicesCompiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor ServicesEelco Visser
 
Lex and Yacc ppt
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc pptpssraikar
 
C language
C languageC language
C languageSMS2007
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingEelco Visser
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++HalaiHansaika
 
Introduction of bison
Introduction of bisonIntroduction of bison
Introduction of bisonvip_du
 
Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)omercomail
 

What's hot (20)

Verilogspk1
Verilogspk1Verilogspk1
Verilogspk1
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
 
Introduction of flex
Introduction of flexIntroduction of flex
Introduction of flex
 
Hardware Description Language
Hardware Description Language Hardware Description Language
Hardware Description Language
 
C language
C languageC language
C language
 
Verilog
VerilogVerilog
Verilog
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
 
Digital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language VerilogDigital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language Verilog
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
An Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprAn Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl ppr
 
Compiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor ServicesCompiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor Services
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Lex and Yacc ppt
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc ppt
 
C language
C languageC language
C language
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
 
Introduction of bison
Introduction of bisonIntroduction of bison
Introduction of bison
 
Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)
 

Viewers also liked

Computer Organization and Assembly Language
Computer Organization and Assembly LanguageComputer Organization and Assembly Language
Computer Organization and Assembly Languagefasihuddin90
 
Data representation
Data representationData representation
Data representationrozanadiana
 
Fingerprint Attendance System - the hand-held device for classroom attendance
Fingerprint Attendance System - the hand-held device for classroom attendanceFingerprint Attendance System - the hand-held device for classroom attendance
Fingerprint Attendance System - the hand-held device for classroom attendancemohamedbasheerkp
 
[1] Data Representation
[1] Data Representation[1] Data Representation
[1] Data RepresentationMr McAlpine
 
15.project attendence managemnt system
15.project attendence managemnt system15.project attendence managemnt system
15.project attendence managemnt systemHaseeb Nasir
 
fingerprint classification systems Henry and NCIC
fingerprint classification systems Henry and NCICfingerprint classification systems Henry and NCIC
fingerprint classification systems Henry and NCICKUL2700
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1Motaz Saad
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)Ashim Saha
 

Viewers also liked (11)

Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
Computer Organization and Assembly Language
Computer Organization and Assembly LanguageComputer Organization and Assembly Language
Computer Organization and Assembly Language
 
Data representation
Data representationData representation
Data representation
 
Fingerprint Attendance System - the hand-held device for classroom attendance
Fingerprint Attendance System - the hand-held device for classroom attendanceFingerprint Attendance System - the hand-held device for classroom attendance
Fingerprint Attendance System - the hand-held device for classroom attendance
 
[1] Data Representation
[1] Data Representation[1] Data Representation
[1] Data Representation
 
15.project attendence managemnt system
15.project attendence managemnt system15.project attendence managemnt system
15.project attendence managemnt system
 
fingerprint classification systems Henry and NCIC
fingerprint classification systems Henry and NCICfingerprint classification systems Henry and NCIC
fingerprint classification systems Henry and NCIC
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Fingerprint
FingerprintFingerprint
Fingerprint
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
 

Similar to C language (20)

02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
 
C
CC
C
 
Functions
FunctionsFunctions
Functions
 
Functions
FunctionsFunctions
Functions
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
 
85ec7 session2 c++
85ec7 session2 c++85ec7 session2 c++
85ec7 session2 c++
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
C programming
C programmingC programming
C programming
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
 
Functions-.pdf
Functions-.pdfFunctions-.pdf
Functions-.pdf
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
1 c prog1
1 c prog11 c prog1
1 c prog1
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 

More from Robo India

Servo Based 5 Axis Robotic Arm Project Report
Servo Based 5 Axis Robotic Arm Project ReportServo Based 5 Axis Robotic Arm Project Report
Servo Based 5 Axis Robotic Arm Project ReportRobo India
 
A project report on energy meter monitoring online using wireless transmissio...
A project report on energy meter monitoring online using wireless transmissio...A project report on energy meter monitoring online using wireless transmissio...
A project report on energy meter monitoring online using wireless transmissio...Robo India
 
A project report on wireless energy meter reading using x bee
A project report on wireless energy meter reading using x beeA project report on wireless energy meter reading using x bee
A project report on wireless energy meter reading using x beeRobo India
 
PC Based Industrial Automation With AVR Atmega 16 - Project Report
PC Based Industrial Automation With AVR Atmega 16 - Project ReportPC Based Industrial Automation With AVR Atmega 16 - Project Report
PC Based Industrial Automation With AVR Atmega 16 - Project ReportRobo India
 
Indian Banks Taglines and Punch Lines
Indian Banks Taglines and Punch LinesIndian Banks Taglines and Punch Lines
Indian Banks Taglines and Punch LinesRobo India
 
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...Robo India
 
Understanding GPS & NMEA Messages and Algo to extract Information from NMEA.
Understanding GPS & NMEA Messages and Algo to extract Information from NMEA.Understanding GPS & NMEA Messages and Algo to extract Information from NMEA.
Understanding GPS & NMEA Messages and Algo to extract Information from NMEA.Robo India
 
Relay and AVR Atmel Atmega 16
Relay and AVR Atmel Atmega 16Relay and AVR Atmel Atmega 16
Relay and AVR Atmel Atmega 16Robo India
 
DTMF - Dual Tone Multi Frequency Signaling and AVR Atmel Atmega16multi-freque...
DTMF - Dual Tone Multi Frequency Signaling and AVR Atmel Atmega16multi-freque...DTMF - Dual Tone Multi Frequency Signaling and AVR Atmel Atmega16multi-freque...
DTMF - Dual Tone Multi Frequency Signaling and AVR Atmel Atmega16multi-freque...Robo India
 
Servo motor and AVR Atmel Atmega 16
Servo motor and AVR  Atmel Atmega 16Servo motor and AVR  Atmel Atmega 16
Servo motor and AVR Atmel Atmega 16Robo India
 
IR Sensor Working and Concepts
IR Sensor Working and ConceptsIR Sensor Working and Concepts
IR Sensor Working and ConceptsRobo India
 
Digital and Analog IR Sensor Working and Cocepts
Digital and Analog IR Sensor Working and Cocepts Digital and Analog IR Sensor Working and Cocepts
Digital and Analog IR Sensor Working and Cocepts Robo India
 
ADC - Analog to Digital Conversion on AVR microcontroller Atmega16
ADC - Analog to Digital  Conversion on AVR microcontroller Atmega16ADC - Analog to Digital  Conversion on AVR microcontroller Atmega16
ADC - Analog to Digital Conversion on AVR microcontroller Atmega16Robo India
 
LCD Theory and Working Principles
LCD Theory and Working PrinciplesLCD Theory and Working Principles
LCD Theory and Working PrinciplesRobo India
 
Led Theory and Working Principles
Led Theory and Working PrinciplesLed Theory and Working Principles
Led Theory and Working PrinciplesRobo India
 
Fundamentals of embedded system and electronics
Fundamentals of embedded system and electronicsFundamentals of embedded system and electronics
Fundamentals of embedded system and electronicsRobo India
 
Single bit oprations in avr microcontroller
Single bit oprations in avr microcontrollerSingle bit oprations in avr microcontroller
Single bit oprations in avr microcontrollerRobo India
 
Input Output programming in AVR microcontroller
Input  Output  programming in AVR microcontrollerInput  Output  programming in AVR microcontroller
Input Output programming in AVR microcontrollerRobo India
 
Marketing to youth
Marketing to youthMarketing to youth
Marketing to youthRobo India
 

More from Robo India (20)

Robot Motions
Robot MotionsRobot Motions
Robot Motions
 
Servo Based 5 Axis Robotic Arm Project Report
Servo Based 5 Axis Robotic Arm Project ReportServo Based 5 Axis Robotic Arm Project Report
Servo Based 5 Axis Robotic Arm Project Report
 
A project report on energy meter monitoring online using wireless transmissio...
A project report on energy meter monitoring online using wireless transmissio...A project report on energy meter monitoring online using wireless transmissio...
A project report on energy meter monitoring online using wireless transmissio...
 
A project report on wireless energy meter reading using x bee
A project report on wireless energy meter reading using x beeA project report on wireless energy meter reading using x bee
A project report on wireless energy meter reading using x bee
 
PC Based Industrial Automation With AVR Atmega 16 - Project Report
PC Based Industrial Automation With AVR Atmega 16 - Project ReportPC Based Industrial Automation With AVR Atmega 16 - Project Report
PC Based Industrial Automation With AVR Atmega 16 - Project Report
 
Indian Banks Taglines and Punch Lines
Indian Banks Taglines and Punch LinesIndian Banks Taglines and Punch Lines
Indian Banks Taglines and Punch Lines
 
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
Evaluation of dynamics | Gyroscope, Accelerometer, Inertia Measuring Unit and...
 
Understanding GPS & NMEA Messages and Algo to extract Information from NMEA.
Understanding GPS & NMEA Messages and Algo to extract Information from NMEA.Understanding GPS & NMEA Messages and Algo to extract Information from NMEA.
Understanding GPS & NMEA Messages and Algo to extract Information from NMEA.
 
Relay and AVR Atmel Atmega 16
Relay and AVR Atmel Atmega 16Relay and AVR Atmel Atmega 16
Relay and AVR Atmel Atmega 16
 
DTMF - Dual Tone Multi Frequency Signaling and AVR Atmel Atmega16multi-freque...
DTMF - Dual Tone Multi Frequency Signaling and AVR Atmel Atmega16multi-freque...DTMF - Dual Tone Multi Frequency Signaling and AVR Atmel Atmega16multi-freque...
DTMF - Dual Tone Multi Frequency Signaling and AVR Atmel Atmega16multi-freque...
 
Servo motor and AVR Atmel Atmega 16
Servo motor and AVR  Atmel Atmega 16Servo motor and AVR  Atmel Atmega 16
Servo motor and AVR Atmel Atmega 16
 
IR Sensor Working and Concepts
IR Sensor Working and ConceptsIR Sensor Working and Concepts
IR Sensor Working and Concepts
 
Digital and Analog IR Sensor Working and Cocepts
Digital and Analog IR Sensor Working and Cocepts Digital and Analog IR Sensor Working and Cocepts
Digital and Analog IR Sensor Working and Cocepts
 
ADC - Analog to Digital Conversion on AVR microcontroller Atmega16
ADC - Analog to Digital  Conversion on AVR microcontroller Atmega16ADC - Analog to Digital  Conversion on AVR microcontroller Atmega16
ADC - Analog to Digital Conversion on AVR microcontroller Atmega16
 
LCD Theory and Working Principles
LCD Theory and Working PrinciplesLCD Theory and Working Principles
LCD Theory and Working Principles
 
Led Theory and Working Principles
Led Theory and Working PrinciplesLed Theory and Working Principles
Led Theory and Working Principles
 
Fundamentals of embedded system and electronics
Fundamentals of embedded system and electronicsFundamentals of embedded system and electronics
Fundamentals of embedded system and electronics
 
Single bit oprations in avr microcontroller
Single bit oprations in avr microcontrollerSingle bit oprations in avr microcontroller
Single bit oprations in avr microcontroller
 
Input Output programming in AVR microcontroller
Input  Output  programming in AVR microcontrollerInput  Output  programming in AVR microcontroller
Input Output programming in AVR microcontroller
 
Marketing to youth
Marketing to youthMarketing to youth
Marketing to youth
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 

C language

  • 1.
  • 2. • 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
  • 3.
  • 4. • Developed between 1969 and 1973 along with Unix • Due mostly to Dennis Ritchie • Designed for systems programming – Operating systems – Utility programs – Compilers – Filters • Evolved from B, which evolved from BCPL
  • 6. • The files that are specified in the include section is called as header file • These are precompiled files that has some functions defined in them • We can call those functions in our program by supplying parameters • Header file is given an extension .h • C Source file is given an extension .c
  • 7. • This is the entry point of a program • When a file is executed, the start point is the main function • From main function the flow goes as per the programmers choice. • There may or may not be other functions written by user in a program • Main function is compulsory for any c program
  • 8. #include<stdio.h> int main() { printf(“Hello”); return 0; } • This program prints Hello on the screen when we execute it
  • 9. • Type a program • Save it • Compile the program – This will generate an exe file (executable) • Run the program (Actually the exe created out of compilation will run and not the .c file) • In different compiler we have different option for compiling and running. We give only the concepts.
  • 10. • Single line comment – // (double slash) – Termination of comment is by pressing enter key • Multi line comment /*…. …….*/ This can span over to multiple lines
  • 11.
  • 12. • arithmetic: + – * / % • comparison: == != < <= > >= • bitwise logical: & | ^ ~ • shifting: << >> • lazy logical: && || ! • conditional: ? : • assignment: = += -= • increment/decrement: ++ -- • sequencing: , • pointer: * -> & []
  • 13. • and: & • or: | • xor: ^ • not: ~ • left shift: << • right shift: >> • Useful for bit-field manipulations #define MASK 0x040 if (a & MASK) { … } /* Check bits */ c |= MASK; /* Set bits */ c &= ~MASK; /* Clear bits */ d = (a & MASK) >> 4; /* Select field */
  • 14. • Syntax: condition ? result1 : result2 If the condition is true, result1 is returned else result2 is returned. • 10==5 ? 11: 12 10!=5 ? 4 : 3 12>8 ? a : b
  • 15.
  • 16. • A data type defines a collection of data objects and a set of predefined operations on those objects.
  • 17.
  • 18. • Variables are data that will keep on changing • Declaration <<Data type>> <<variable name>>; int a; • Definition <<varname>>=<<value>>; a=10; • Usage <<varname>> a=a+1; //increments the value of a by 1
  • 19. • Should not be a reserved word like int etc.. • Should start with a letter or an underscore(_) • Can contain letters, numbers or underscore. • No other special characters are allowed including space • Variable names are case sensitive – A and a are different.
  • 20. • char ch; • int i; • i = ‘a’; /* i is now 97 */ • ch = 65; /* ch is now ‘A’ */ • ch = ch + 1; /* ch is now ‘B’ */ • ch++; /* ch is now ‘C’ */ • if(‘a’ <= ch && ch <= ‘z’) • for(ch = ‘A’; ch <= ‘Z’; ch++)
  • 21.
  • 22. • The syntax of for loop is for(initialisation;condition checking;increment) { set of statements } Eg: Program to print Hello 10 times for(I=0;I<10;I++) { printf(“Hello”); }
  • 23. • The syntax of do while loop do { set of statements }while(condn); Eg: i=10; Output: do 10987654321 { printf(“%d”,i); i--; }while(i!=0)
  • 24. if (condition) { stmt 1; //Executes if Condition is true } else { stmt 2; //Executes if condition is false }
  • 25. switch(var) { case 1: //if var=1 this case executes stmt; break; case 2: //if var=2 this case executes stmt; break; default: //if var is something else this will execute stmt; }
  • 26. • When the break statement is executed inside a loop-statement, the loop-statement is terminated immediately • The execution of the program will continue with the statement following the loop- statement • Syntax : break;
  • 27.
  • 28. •When the continue statement is executed inside a loop-statement, the program will skip over the remainder of the loop-body to the end of the loop. •Syntax Continue;
  • 29.
  • 30.
  • 31. • Array – Group of consecutive memory locations – Same name and type • To refer to an element, specify – Array name – Position number • Format: arrayname[ position number ] – First element at position 0 – n element array named c: • c[ 0 ], c[ 1 ]...c[ n – 1 ]
  • 32.
  • 33. • When declaring arrays, specify – Name – Type of array – Number of elements arrayType arrayName[ numberOfElements ]; – Examples: int c[ 10 ]; float myArray[ 3284 ]; • Declaring multiple arrays of same type – Format similar to regular variables – Example: int b[ 100 ], x[ 27 ];
  • 34. • Initializers int n[ 5 ] = { 1, 2, 3, 4, 5 }; – If not enough initializers, rightmost elements become 0 int n[ 5 ] = { 0 } • All elements 0 – If too many a syntax error is produced syntax error – C arrays have no bounds checking • If size omitted, initializers determine it int n[ ] = { 1, 2, 3, 4, 5 }; – 5 initializers, therefore 5 element array
  • 35. • Initialization – int b[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } }; – Initializers grouped by row in braces – If not enough, unspecified elements set to zero int b[ 2 ][ 2 ] = { { 1 }, { 3, 4 } }; • Referencing elements – Specify row, then column printf( "%d", b[ 0 ][ 1 ] ); 1 2 3 4 1 0 3 4
  • 36. So far we have used one-dimensional (1D) arrays, but we can also use arrays with 2 or more dimensions. 2D arrays essentially correspond to matrices. Example: • int A; // single variable • int B[6]; // 1D array • int C[3][4]; // 2D array (matrix) • int D[3][4][5]; // 3D array • int E[3][4][5][3]; // 4D array • //etc
  • 37.
  • 38.
  • 39. • A string is a sequence of characters treated as a group • array can be of any length • end of string is indicated by a delimiter, the zero character ‘0’ "A String" A 0gnirtS
  • 40. • String literal values are represented by sequences of characters between double quotes (“) • Examples – “” - empty string – “hello” • “a” versus ‘a’ – ‘a’ is a single character value (stored in 1 byte) as the ASCII value for a – “a” is an array with two characters, the first is a, the second is the character value 0
  • 41. • Allocate an array of a size large enough to hold the string (plus 1 extra value for the delimiter) • Examples (with initialization): char str1[6] = “Hello”; char str2[] = “Hello”; char *str3 = “Hello”; char str4[6] = {‘H’,’e’,’l’,’l’,’o’,’0’};
  • 42. • C provides a wide range of string functions for performing different string tasks • Examples – strlen(str) – To find length of string str – strrev(str) – Reverses the string str as rts – strcat(str1,str2) – Appends str2 to str1 and returns str1 – strcpy(st1,st2) – copies the content of st2 to st1 – strcmp(s1,s2) – Compares the two string s1 and s2 – strcmpi(s1,s2) – Case insensitive comparison of strings • Functions come from the utility library string.h – #include <string.h> to use
  • 43.
  • 44. • A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address. The general form of a pointer variable declaration is: • type *var-name;
  • 45. • There are few important operations, which we will do with the help of pointers very frequently. • we define a pointer variable • assign the address of a variable to a pointer • finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand. Following example makes use of these operations:
  • 46.
  • 47.
  • 48. • Functions – Modularize a program – All variables declared inside functions are local variables • Known only in function defined – Parameters • Communicate information between functions • Local variables • Benefits of functions – Divide and conquer • Manageable program development – Software reusability • Use existing functions as building blocks for new programs • Abstraction - hide internal details (library functions) – Avoid code repetition
  • 49. • Function definition format return-value-type function-name( parameter-list ) { declarations and statements } – Function-name: any valid identifier – Return-value-type: data type of the result (default int) • void – indicates that the function returns nothing – Parameter-list: comma separated list, declares parameters • A type must be listed explicitly for each parameter unless, the parameter is of type int
  • 50. • Function definition format (continued) return-value-type function-name( parameter-list ) { declarations and statements } – Declarations and statements: function body (block) • Variables can be declared inside blocks (can be nested) • Functions can not be defined inside other functions – Returning control • If nothing returned – return; – or, until reaches right brace • If something returned – return expression;
  • 51. • Call by value – Copy of argument passed to function – Changes in function do not effect original – Use when function does not need to modify argument • Avoids accidental changes • Call by reference – Passes original argument – Changes in function effect original – Only used with trusted functions
  • 52. • Recursive functions – Functions that call themselves – Can only solve a base case – Divide a problem up into • What it can do • What it cannot do – What it cannot do resembles original problem – The function launches a new copy of itself (recursion step) to solve what it cannot do – Eventually base case gets solved • Gets plugged in, works its way up and solves whole problem
  • 53. • Example: factorials – 5! = 5 * 4 * 3 * 2 * 1 – Notice that • 5! = 5 * 4! • 4! = 4 * 3! ... – Can compute factorials recursively – Solve base case (1! = 0! = 1) then plug in • 2! = 2 * 1! = 2 * 1 = 2; • 3! = 3 * 2! = 3 * 2 = 6;
  • 54.
  • 55. • A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together.
  • 56. • Structures are user defined data types • It is a collection of heterogeneous data • It can have integer, float, double or character data in it • We can also have array of structures struct <<structname>> { members; }element; We can access element.members;
  • 57. •Compound data: •A date is – an int month and – an int day and – an int year
  • 58. • The typedef operator is used for creating alias of a data type • For example I have this statement typedef int integer; Now I can use integer in place of int i.e instead of declaring int a;, I can use integer a; This is applied for structures too.
  • 59. • typedef struct student • { • int id; • Char name[10]; • }s; • Now I can put • s s1,s2;
  • 60. • A union value doesn’t “know” which case it contains •Choices: •An element is – an int i or – a char c union AnElt { int i; char c; } elt1, elt2; elt1.i = 4; elt2.c = ’a’; elt2.i = 0xDEADBEEF; if (elt1 currently has a char) …
  • 61.
  • 62. Symbolic constants #define PI 3.1415926535 Macros with arguments for emulating inlining #define min(x,y) ((x) < (y) ? (x) : (y)) Conditional compilation #ifdef __STDC__ File inclusion for sharing of declarations #include “myheaders.h”
  • 63. Header file dependencies usually form a directed acyclic graph (DAG) How do you avoid defining things twice? Convention: surround each header (.h) file with a conditional: #ifndef __MYHEADER_H__ #define __MYHEADER_H__ /* Declarations */ #endif