SlideShare a Scribd company logo
C Programming
By
Mrs. B. Dhivya M.C.A., M.Phil.,
Technical Trainer / Assistant Professor, CTPCR
Sri Ramakrishna College of Arts & Science, Coimbatore.
Data Types and Variables
Data types in C
• Each variable in C has an associated data type.
It specifies the type of data that the variable
can store .
• Each data type requires different amounts of
memory.
Why Data Types?
• Every variable must have a type.
• Every variable should get some space in the
memory.
• Help the compiler decide how many bits
should be reserved for a variable.
Datatypes in C
• Primary datatype
• Derived datatype
• User defined datatype
Datatypes in C (contd..)
Integer Data Type
• Range: -2,147,483,648 to 2,147,483,647
• Size: 4 bytes
• Format Specifier: %d
eg:
int var_name;
int a;
Character Data Type
• Character data type allows its variable to store
only a single character.
• Range: (-128 to 127) or (0 to 255)
• Size: 1 byte
• Format Specifier: %c
Eg:
char var_name;
char a;
Float Data Type
Float in C is used to store decimal and exponential values.
Range: 1.2E-38 to 3.4E+38
Size: 4 bytes
Format Specifier: %f
Eg:
float a;
Double Data Type
Double has more precision as compared to that float
then it is much more obvious that it occupies twice the
memory occupied by the floating-point type.
Range: 1.7E-308 to 1.7E+308
Size: 8 bytes
Format Specifier: %lf
Eg:
double var_name;
double a;
Void Data Type
•The void data type in C is used to specify that no value is
present. It does not provide a result value to its caller.
•It has no values and no operations.
// function return type void
void exit(int check);
// Function without any parameter can accept void.
int print(void);
// memory allocation function which
// returns a pointer to void.
void *malloc (size_t size);
Size of Data Types in C
•The size of the data types in C is dependent on the size of the
architecture.
•sizeof() operator to check the size of the data types.
Eg:
printf("Size of int: %zu bytesn", sizeof(int));
Derived data types
• Array
•Pointers
•Structures
•Union
Userdefined data types
• function
•Enum
•Type def
Variables in C
•A variable is a name of the memory location. It
is used to store data. Its value can be changed,
and it can be reused many times.
Eg;
int a;
float b;
char d;
Types of Variables in C
There are many types of variables in c:
•local variable
•global variable
•static variable
•automatic variable
•external variable
Output?
#include <stdio.h>
int main() {
int arr[10];
double dArr[5];
printf("Size of arr: %zu bytesn", sizeof(arr));
printf("Size of dArr: %zu bytesn", sizeof(dArr));
return 0;
}
Output:
Size of arr: 40 bytes
Size of dArr: 40 bytes
Output?
#include <stdio.h>
int main() {
printf("Size of int: %zu bytesn", sizeof(int));
printf("Size of char: %zu byten", sizeof(char));
printf("Size of float: %zu bytesn", sizeof(float));
printf("Size of double: %zu bytesn", sizeof(double));
return 0;
} Output:
Size of int: 4 bytes
Size of char: 1 byte
Size of float: 4 bytes
Size of double: 8 bytes
Output?
#include <stdio.h>
int main() {
int x = 10;
double y = 12.34;
char z = 'A';
printf("Size of x: %zu bytesn", sizeof(x));
printf("Size of y: %zu bytesn", sizeof(y));
printf("Size of z: %zu byten", sizeof(z));
return 0;
}
Output:
Size of x: 4 bytes
Size of y: 8 bytes
Size of z: 1 byte
Predict the Output or error of the C Program
1) #include <stdio.h>
int main() {
int x = 2147483647;
x = x + 1;
printf("%dn", x);
return 0;
}
A) Compiler Error
B) -2147483648
C) 2147483648
D) Undefined Behavior
Output:
-2147483648
it overflows and wraps
around to the minimum
value of a signed int, which
is -2147483648.
This is an example of signed
integer overflow.
2) #include <stdio.h>
int main() {
unsigned int x = 4294967295;
x = x + 1;
printf("%un", x);
return 0;
}
Output:
0
3. #include <stdio.h>
int main() {
int x = 5 / 2;
printf("%dn", x);
return 0;
}
A) 2
B) 2.5
C) 2.0
D) Compiler Error
Answer: A) 2
4) #include <stdio.h>
int main() {
int x = -3 % 2;
printf("%dn", x);
return 0;
}
A) -1
B) 1
C) 0
D) Compiler Error
Answer: -1
5) #include <stdio.h>
int main() {
float x = 1.1;
printf("%fn", x);
return 0;
}
A) 1.1
B) 1.100000
C) Compiler Error
D) Undefined Behavior
Answer:
1.100000
6) #include <stdio.h>
int main() {
float x = 0.1;
if (x == 0.1)
printf("Equaln");
else
printf("Not Equaln");
return 0;
}
Answer:
Not equal
7) #include <stdio.h>
int main() {
float x = 1.0 / 0.0;
printf("%fn", x);
return 0;
}
Answer:
Infinity
8) #include <stdio.h>
int main() {
float x = 0.0 / 0.0;
printf("%fn", x);
return 0;
}
Answer:
NaN ( not a number)
9) #include <stdio.h>
int main() {
double x = 1.0 / 3.0;
printf("%.10fn", x);
return 0;
}
Answer:
0.3333333333
10) #include <stdio.h>
int main() {
char ch = 'A';
printf("%cn", ch + 1);
return 0;
}
A) A
B) B
C) 66
D) Compiler Error
Answer:
B
11) #include <stdio.h>
int main() {
char ch = 128;
printf("%dn", ch);
return 0;
}
A) 128
B) -128
C) Compiler Error
D) Undefined Behavior
Answer:
B) -128
12) #include <stdio.h>
int main()
{
float c = 5.0;
printf ("Temperature in Fahrenheit is %.2f",
(9/5)*c + 32);
return 0;
}
(A) Temperature in Fahrenheit is 41.00
(B) Temperature in Fahrenheit is 37.00
(C) Temperature in Fahrenheit is 0.00
(D) Compiler Error
Answer:
B)
Assessment 1
1. Program to check if the given number is prime or not.
2. Program to find factorial of a number in C.

More Related Content

PPTX
C language
PPTX
C programming language tutorial
PPTX
Programming_in_C_language_Unit5.pptx course ATOT
PPTX
Unit No 2.pptx Basic s of C Programming
DOCX
PPTX
C introduction by thooyavan
PPTX
C programming language
PDF
Lec-1c.pdf
C language
C programming language tutorial
Programming_in_C_language_Unit5.pptx course ATOT
Unit No 2.pptx Basic s of C Programming
C introduction by thooyavan
C programming language
Lec-1c.pdf

Similar to C Programming : data types and types of variable.pptx (20)

PPT
Introduction to C
PDF
Introduction to programming c and data-structures
ODP
C prog ppt
PDF
Introduction to programming c and data structures
PPTX
C PROGRAMING.pptx
PPT
Introduction to C Programming
PPT
Unit 4 Foc
PPTX
structured Programming Unit-2-Basic-Elements-of-C.pptx
PPSX
Esoft Metro Campus - Certificate in c / c++ programming
PPTX
PPTX
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
PDF
0100_Embeded_C_CompilationProcess.pdf
PDF
C programming day#1
PPTX
C_Programming_Language_tutorial__Autosaved_.pptx
PDF
C-PPT.pdf
PDF
Data structure & Algorithms - Programming in C
PPTX
PPTX
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
PPTX
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
Introduction to C
Introduction to programming c and data-structures
C prog ppt
Introduction to programming c and data structures
C PROGRAMING.pptx
Introduction to C Programming
Unit 4 Foc
structured Programming Unit-2-Basic-Elements-of-C.pptx
Esoft Metro Campus - Certificate in c / c++ programming
4 Introduction to C.pptxSSSSSSSSSSSSSSSS
0100_Embeded_C_CompilationProcess.pdf
C programming day#1
C_Programming_Language_tutorial__Autosaved_.pptx
C-PPT.pdf
Data structure & Algorithms - Programming in C
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Spectroscopy.pptx food analysis technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Getting Started with Data Integration: FME Form 101
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation theory and applications.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectroscopy.pptx food analysis technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Group 1 Presentation -Planning and Decision Making .pptx
Encapsulation_ Review paper, used for researhc scholars
Programs and apps: productivity, graphics, security and other tools
Assigned Numbers - 2025 - Bluetooth® Document
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
Getting Started with Data Integration: FME Form 101
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation theory and applications.pdf
1. Introduction to Computer Programming.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Ad

C Programming : data types and types of variable.pptx

  • 1. C Programming By Mrs. B. Dhivya M.C.A., M.Phil., Technical Trainer / Assistant Professor, CTPCR Sri Ramakrishna College of Arts & Science, Coimbatore. Data Types and Variables
  • 2. Data types in C • Each variable in C has an associated data type. It specifies the type of data that the variable can store . • Each data type requires different amounts of memory.
  • 3. Why Data Types? • Every variable must have a type. • Every variable should get some space in the memory. • Help the compiler decide how many bits should be reserved for a variable.
  • 4. Datatypes in C • Primary datatype • Derived datatype • User defined datatype
  • 5. Datatypes in C (contd..)
  • 6. Integer Data Type • Range: -2,147,483,648 to 2,147,483,647 • Size: 4 bytes • Format Specifier: %d eg: int var_name; int a;
  • 7. Character Data Type • Character data type allows its variable to store only a single character. • Range: (-128 to 127) or (0 to 255) • Size: 1 byte • Format Specifier: %c Eg: char var_name; char a;
  • 8. Float Data Type Float in C is used to store decimal and exponential values. Range: 1.2E-38 to 3.4E+38 Size: 4 bytes Format Specifier: %f Eg: float a;
  • 9. Double Data Type Double has more precision as compared to that float then it is much more obvious that it occupies twice the memory occupied by the floating-point type. Range: 1.7E-308 to 1.7E+308 Size: 8 bytes Format Specifier: %lf Eg: double var_name; double a;
  • 10. Void Data Type •The void data type in C is used to specify that no value is present. It does not provide a result value to its caller. •It has no values and no operations. // function return type void void exit(int check); // Function without any parameter can accept void. int print(void); // memory allocation function which // returns a pointer to void. void *malloc (size_t size);
  • 11. Size of Data Types in C •The size of the data types in C is dependent on the size of the architecture. •sizeof() operator to check the size of the data types. Eg: printf("Size of int: %zu bytesn", sizeof(int));
  • 12. Derived data types • Array •Pointers •Structures •Union
  • 13. Userdefined data types • function •Enum •Type def
  • 14. Variables in C •A variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times. Eg; int a; float b; char d;
  • 15. Types of Variables in C There are many types of variables in c: •local variable •global variable •static variable •automatic variable •external variable
  • 16. Output? #include <stdio.h> int main() { int arr[10]; double dArr[5]; printf("Size of arr: %zu bytesn", sizeof(arr)); printf("Size of dArr: %zu bytesn", sizeof(dArr)); return 0; } Output: Size of arr: 40 bytes Size of dArr: 40 bytes
  • 17. Output? #include <stdio.h> int main() { printf("Size of int: %zu bytesn", sizeof(int)); printf("Size of char: %zu byten", sizeof(char)); printf("Size of float: %zu bytesn", sizeof(float)); printf("Size of double: %zu bytesn", sizeof(double)); return 0; } Output: Size of int: 4 bytes Size of char: 1 byte Size of float: 4 bytes Size of double: 8 bytes
  • 18. Output? #include <stdio.h> int main() { int x = 10; double y = 12.34; char z = 'A'; printf("Size of x: %zu bytesn", sizeof(x)); printf("Size of y: %zu bytesn", sizeof(y)); printf("Size of z: %zu byten", sizeof(z)); return 0; } Output: Size of x: 4 bytes Size of y: 8 bytes Size of z: 1 byte
  • 19. Predict the Output or error of the C Program 1) #include <stdio.h> int main() { int x = 2147483647; x = x + 1; printf("%dn", x); return 0; } A) Compiler Error B) -2147483648 C) 2147483648 D) Undefined Behavior Output: -2147483648 it overflows and wraps around to the minimum value of a signed int, which is -2147483648. This is an example of signed integer overflow.
  • 20. 2) #include <stdio.h> int main() { unsigned int x = 4294967295; x = x + 1; printf("%un", x); return 0; } Output: 0
  • 21. 3. #include <stdio.h> int main() { int x = 5 / 2; printf("%dn", x); return 0; } A) 2 B) 2.5 C) 2.0 D) Compiler Error Answer: A) 2
  • 22. 4) #include <stdio.h> int main() { int x = -3 % 2; printf("%dn", x); return 0; } A) -1 B) 1 C) 0 D) Compiler Error Answer: -1
  • 23. 5) #include <stdio.h> int main() { float x = 1.1; printf("%fn", x); return 0; } A) 1.1 B) 1.100000 C) Compiler Error D) Undefined Behavior Answer: 1.100000
  • 24. 6) #include <stdio.h> int main() { float x = 0.1; if (x == 0.1) printf("Equaln"); else printf("Not Equaln"); return 0; } Answer: Not equal
  • 25. 7) #include <stdio.h> int main() { float x = 1.0 / 0.0; printf("%fn", x); return 0; } Answer: Infinity
  • 26. 8) #include <stdio.h> int main() { float x = 0.0 / 0.0; printf("%fn", x); return 0; } Answer: NaN ( not a number)
  • 27. 9) #include <stdio.h> int main() { double x = 1.0 / 3.0; printf("%.10fn", x); return 0; } Answer: 0.3333333333
  • 28. 10) #include <stdio.h> int main() { char ch = 'A'; printf("%cn", ch + 1); return 0; } A) A B) B C) 66 D) Compiler Error Answer: B
  • 29. 11) #include <stdio.h> int main() { char ch = 128; printf("%dn", ch); return 0; } A) 128 B) -128 C) Compiler Error D) Undefined Behavior Answer: B) -128
  • 30. 12) #include <stdio.h> int main() { float c = 5.0; printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32); return 0; } (A) Temperature in Fahrenheit is 41.00 (B) Temperature in Fahrenheit is 37.00 (C) Temperature in Fahrenheit is 0.00 (D) Compiler Error Answer: B)
  • 31. Assessment 1 1. Program to check if the given number is prime or not. 2. Program to find factorial of a number in C.