SECTION C – LONG ANSWERS
Q3: Data Types in C
1. Basic Data Types
Basic data types are the simplest types in C language.
They include int, float, and char.
These are used to store numbers and characters in programs.
2. Derived Data Types
Derived data types are made from basic data types.
Examples include arrays, pointers, and functions.
They help in handling more complex data structures.
3. User-defined Data Types
These types are created by the programmer.
Examples include struct, union, and enum.
They help in organizing related data into one unit.
4. Void Data Type
Void means no value or empty type.
It is mainly used in functions that do not return anything.
Example: void main() shows no return value.
5. Importance of Data Types
Data types define how much memory is needed.
They also control what type of data can be stored.
This helps avoid errors and improves program efficiency.
6. Example of Data Types
Example: int a = 10 stores an integer value.
float b = 5.5 stores decimal value.
char c = 'A' stores a single character.
Q4: Format Specifiers
1. Definition of Format Specifiers
Format specifiers are special symbols used in C language.
They are used with input and output functions.
They tell the compiler what type of data is being used.
2. Common Format Specifiers
Some common specifiers are %d, %f, and %c.
%d is used for integers, %f for floats.
%c is used for characters in programs.
3. Use in printf Function
Format specifiers are used to display output.
Example: printf("%d", a) prints an integer value.
They help show correct data on the screen.
4. Use in scanf Function
They are also used to take input from the user.
Example: scanf("%d", &a;) reads integer input.
They ensure correct input type is stored.
5. Importance of Format Specifiers
They prevent wrong data display.
They make programs more accurate and reliable.
Without them, output and input can be incorrect.
6. Example Program
int a = 5;
printf("Value = %d", a);
This program prints the value of variable a.
It uses %d to correctly display integer output.