L02 - Variables, Data Types
L02 - Variables, Data Types
Opverse - Tech
Variable
Variables are named memory locations
that have a type, such as integer, float and
character
Variable
Variable
Variable Declaration
data_type variable_name;
int age;
float height;
char grade;
Variable Declaration
Variable Declaration
Variable Declaration
Variable Declaration
Variable initialization
int age;
float height;
char grade;
age = 10;
height = 5.6;
grade = ‘A’;
Variable Initialization
Variable declaration
and initialization
data_type variable_name = value;
Write a C Program to
add two numbers
Program to add two
numbers
#include <stdio.h>
Link Section
Header Section
Preprocessor Directive
Program to add two
numbers
#include <stdio.h>
Main function
int main()
Program to add two
numbers
#include <stdio.h>
int main()
{ Body of Main
function
}
Program to add two
numbers
inches
#include <stdio.h>
int main( )
{
int a, b, c ;
}
Program to add two
numbers
inches
#include <stdio.h>
a
int main( ) garbage
{ b
int a, b, c ; garbage
c
garbage
}
Program to add two
numbers
inches
#include <stdio.h>
a
int main( ) garbage
{ b
int a, b, c ; garbage
a = 7; c
garbage
}
Program to add two
numbers
inches
#include <stdio.h>
a a
int main( )
garbage 7
{
b
int a, b, c ;
garbage
a = 7; Variable c
initialization
garbage
}
Program to add two
numbers
inches
#include <stdio.h>
a a
int main( )
garbage 7
{
b b
int a, b, c ;
garbage 6
a = 7;
b = 6; c
garbage
}
Program to add two
numbers
inches
#include <stdio.h>
a a
int main( )
garbage 7
{
b b
int a, b, c ;
garbage 6
a = 7;
c c
b = 6;
c = a + b; garbage 13
a+b
} and assigned to c
Program to add two
numbers
inches
#include <stdio.h>
Output:
int main( ) 13
{
int a, b, c ; a
a=7;
7
b=6;
b
c = a + b; 6
printf (“%d”, c) ; c
13
}
Program to add two
numbers
#include <stdio.h>
int main( )
{
Output:
int a, b, c ; 13
a=7;
b=6;
c = a + b;
printf (“%d”, c) ;
return 0 ;
}
Format specifiers start with a percentage % operator
Format Specifier
Format
Description
Specifier
%d Integer Format Specifier
%f Float Format Specifier
%c Character Format Specifier
%s String Format Specifier
%u Unsigned Integer Format Specifier
%ld Long Int Format Specifier