0% found this document useful (0 votes)
5 views24 pages

Slide 2

Uploaded by

farihad99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views24 pages

Slide 2

Uploaded by

farihad99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Variables

Location in the memory where values can be stored


Defining variables

int a;

data type name of the variable


Defining/Declare variables

int a;
variable names
correspond to memory
locations

memory
Data types
Name of variables
A variable name in C can be any valid identifier.
An identifier is a series of characters
consisting of letters (a-z, A- Z), digits (0-9) and
underscores (_) that does not begin with a digit.
Name of variables

int a1;
int 1al
int A1;
int abcdef;
int _ab;
int A1;
Name of variables

int a1; valid


int 1al invalid
int A1; valid
int abcdef; valid
int _ab; valid : but avoid
int A1; valid
Name of variables
C is case sensitive— uppercase and lowercase
letters are different in C
int a1;
int A1;

a1, A1 two different variables


Name of variables:
multiword
int print_sum;
use '_' as the word separator
Name of variables:
Convention
Use all lower case letters
Assigning variables
a = 2;
2
Assign 2 to a

Assignment operator
Initializing variables
int a; //defining variable a
a=2; //assigning 2 to a

Combine variable definition and


variable assignment
int a = 2;

initializing variable a
Declaring multiple variables in
single statement
int a; int a, b;
int b; Data type same

int a; int a;
float b; Data type different float b;
Declare variables
before they are
used
Arithmetic Operation
int sum;
sum = a + b;

Arithmetic operator
Arithmetic Operation
Printing variables
printf(“Sum %d”, sum)

Conversion specifier
Printing multiple variables in single
statement
printf(“a = %d”, a);
printf(“b = %d”, b);
printf(“sum = %d”, sum);

printf(“a = %d, b = %d, c = %d”, a, b,


sum);
Algebraic and C Arithmetic Expressions

AE:

C:
Algebraic and C Arithmetic Expressions

AE:

C:
Algebraic and C Arithmetic Expressions

AE:

C:
Algebraic and C Arithmetic Expressions

AE:

C:
Taking Input from User
printf("Enter integer a : "); Prompt

scanf("%d", &a);

Address operator
Taking Multiple Inputs in a single
statement
scanf("%d", &a);
scanf("%d", &b);

scanf("%d%d", &a, &b);

You might also like