You are on page 1of 26

C programming

Variables and Data Types

Dr. Elham Pashaei


Storing the information you need — Variables
Declaring and Initializing a variable
Rules to name a Variable
Datatype of Variable
Data Type's Size and Range
Data Type Size (bits) Range
char 1 byte or 8 bits -128 to 127
int 2 byte or 16 bits || 4 byte or 32 bits -32768 to 32767 or -2,147,483,648 to 2,147,483,647
-38 +38
float 4 bytes or 32bits || 8 byte or 64 bits 3.4e to 3.4e
-308 +308
double 8 byte or 64 bits 1.7e to 1.7e
What is a signed data type? Using signed data type both positive and negative values we can store.
What is the unsigned data type? Using unsigned data types, we can store only positive values.

If you do not specify whether the variable is a signed variable or an unsigned variable, by default that is a signed variable and can accept
both positive and negative values.

long: This can be used to increased size of the current data type to 2 more bytes, which can be applied on int or double data types.
Data types in C Language
Data type determines the type of data a variable will hold. If a variable x is declared as int. it means x can hold only
integer values. Every variable which is used in the program must be declared as what data-type it is.
printf()

scanf()
Format Specifiers
Format Spectifiers in Programming language tells us which type of data to
store and which type of data to print or to output.
We can use the sizeof() operator to
check the size of a variable
Data Type Keyword Format Specifier
character char %c
signed integer int %d or %i
unsigned integer unsigned int %u or %lu
long double long double %ld
string char %s
floating point float %f
double floating point double %lf
Format String Meaning

%d Scan or print an integer as signed decimal number

%f Scan or print a floating point number

%c To scan or print a character

%s To scan or print a character string. The scanning ends at whitespace.


int a; Scanf (“%i”, & a)

char b; Scanf (“%c”, & b)

float c; Scanf (“%f”, & c)


double c;
int a; Scanf (“%i”, & a) printf(“%i”, a) or printf(“%d”, a)
printf(“integer= %i”, a)

char b; Scanf (“%c”, & b) printf(“%c”, b)


printf(“character = %c \n", b);

float c;
Scanf (“%f”, & c) printf(“%f”, c)
double c;
printf(“float = %f \n", c );
String

char kelime[20]= “Elham Pashaei”; char kelime[20];


Printf(“Lütfen kelime giriniz ”);
s
scanf( "% ", & kelime)
s
printf("kelime = % \n", kelime);
s
printf("kelime = % \n", kelime);

Output: Kelime= Elham Pashaei


Output: Kelime= Elham Pashaei

You might also like