Viva Questions based on C Programming Data Types
1. What are data types in C?
Answer: It defines the type of data that we can store in a variable. They tell the
compiler how much space to allocate and how to interpret the value.
2. What are the different types of data types in C?
Answer:
C has three primary data types:
•
Basic data types: int,
float, char,
double
•
Derived data types: array, pointer, structure, union
•
Enumeration and void types: enum, void
3. What is the size of int, float,
double,
and char
in C?
Answer:
Sizes may vary by system, but typically:
•
int: 4
bytes
•
float: 4
bytes
•
double: 8 bytes
•
char: 1 byte
4. What is the difference between float
and double?
Answer:
•
float is a single-precision (32-bit) floating point.
• double is a double-precision (64-bit) floating point. double is more accurate and can store larger values.
5. What is the use of the void data type?
Answer:
void means “no type.” It is used:
•
In functions that return nothing: void functionName()
•
For generic pointers: void *ptr
6. What is the difference between signed and
unsigned data types?
Answer:
•
Signed data types can store both positive and negative values.
•
Unsigned data types can only store positive values, which allows a
larger positive range.
Example:
signed
int ranges from –2,147,483,648 to 2,147,483,647
unsigned
int ranges from 0 to 4,294,967,295
7. What is the use of sizeof operator?
Answer:
The sizeof operator returns the size (in bytes) of a data type
or variable.
Example:
sizeof(int) gives 4 on most systems.
8. What are type modifiers in C?
Answer:
Type modifiers are keywords that alter the meaning of the base data types.
They
are: signed, unsigned,
long, and
short.
Example:
unsigned long
int increases the range for
positive integers.
9. Can we use char for storing small integers?
Answer:
Yes. A char is 1 byte, so it can store small integer values
(typically –128 to 127 for signed char).
10. What happens if we assign a float
value to an int variable?
Answer:
The decimal part is truncated,
not rounded.
Example:
float x = 5.9;
int y = x; // y becomes 5