10 C Interview Questions and Answers on Data Types
Most of the programmers learn the basics of coding through C programming language. In C programming, data types are system that are used to declare variables of different types. These data type determine how much a variable occupies space in storage and how the execution of stored bit patterns are executed.
If you are looking for a job in programming, you should have a good knowledge in C programming language and to know the basics of data types is a must.
Here we list 10 C interview questions and answers on data types that you can encounter.
1. How many data types are used in C?
Answer: There are four data types in C, namely: Basic types- integer and floating point types, Enumerated types, type void, and derived types- pointer types, array types, structure types, union types and function types.
2. How can you find the exact size of a data type?
Answer: One can determine the exact size of a data type by using the sizeof operator. The storage size of the data type is obtained in bytes by using the syntax: sizeof(data_type).
3. If the size of int data type is two bytes, what is the range of signed int data type?
Answer: -32768 to 32767.
4. What is short int in C programming?
Answer: In C programming, short is a qualifier and int is the basic data type.
5. What is the best way to store flag values in a program?
Answer: Flag values are used to make decisions between two or more options during the execution of a program. Generally, flag values are small (often two) and it tries to save space by not storing each flag according to its own data type.
The best way to store flag values is to keep each of the values in their own integer variable. If there are large number of flags, we can create an array of characters or integers. We can also store flag values by using low-order bits more efficiently.
6. What is bit masking?
Answer: Bit masking refers to selecting a particular set of bits from the byte(s) having many values of bits. Bit masking is used to examine the bit values and can be done by ‘AND’ operation of byte, bitwise.
7. What is the output of the following C program?
const int *p;
Answer: 10. Here, in the syntax const int *p; p is used to keep the address of the constant integer value.
8. If you are to store a number 65000 in a 32-bit system, what data type is most appropriate?
Answer: Unsigned short. It be because 65000 lies in the range of short (16-bit) and occupies less space. Signed short values range from -32768 to 32767 because of which we need to use the unsigned short.
9. Are there any data type in C with variable size?
Answer: Yes. One of the data type with variable size is struct. It is because the size of the structure depends on the fields which can be variable as set by the user.
10. What is the output of the following program?
float num1 = 1.1;
double num2 = 1.1;
printf("C ++ programming");
Answer: C programming. It is because float stores values with 8 place accuracy and occupies 4 byte of memory. But double has 16 place accuracy and occupies 8 bytes.
These 10 C interview questions on data types are to judge your knowledge on how aware you are about using data types in programming. If you are a beginner or an engineering graduate, these questions will surely help you for placements, and competitive examinations.
You should always be aware about the size of data types that can different in 16-bit, 32-bit or 64-bit systems. If you have any related C interview questions on data types, let us know in the comments!