 ## C | Data Types | Quiz Questions

### Question 1

Predict the output of the following program
#include <stdio.h>
int main()
{
printf ("%d %o %x", 72, 72, 72);
return 0;
}

A. 72 110 48
B. 78 113 48
C. 70 110 48
D. 72 112 40

#### Explanation

Here, %d prints out as a decimal number, whereas %o prints octal equivalent of 72 and %x prints hexadecimal equivalent of 72.

### Question 2

Find the output of the following program.
#include <stdio.h>
int main ()
{
printf ("%d %d%d %d", 61, 061, 0x61, 0X61);
return 0;
}

A. 72 32 118 113
B. 61 49 97 97
C. 70 58 114 114
D. 72 58 114 119

#### Explanation

The c programming language has three number systems decimal, octal and hexadecimal. To understand the difference between these numbers octal number is preceded by 0 and the hexadecimal number is preceded by 0x or 0X.

In the above code, 061, 0x61 and 0X61 using format specifier %d. The %d format specifier is used for the decimal number system. Therefore, decimal equivalents of octal 061, 0x61 and 0X61 get printed.

### Question 3

What will be the output of the C program?
#include <stdio.h>
int main ()
{
void number = 11;
printf ("%v", number);
return 0;
}

A. 1
B. 0
C. Garbage value
D. Compilation error

#### Explanation

The void is not a valid data type for declaring variables.

### Question 4

The format identifier "%i" is also used for which data type?
A. char
B. int
C. float
D. double

#### Explanation

"%i" format identifier is used for the int data type.

### Question 5

In C, Size of an integer and a pointer must be same.
A. True
B. False

#### Explanation

The size of the pointer and integer depends on the compiler, it is not necessary that the size of the pointer is the same.

### Question 6

Find the output of the following program?
#include <stdio.h>
int main()
{
float a = 0.5;
if (a==0.5)
printf("True");
else
printf ("False");
return 0;
}

A. True
B. False

### Question 7

Find the output of the following C program
#include <stdio.h>
int main()
{
char b = '\012';
printf ("%d", b);
return 0;
}

A. Compiler error
B. 12
C. 10
D. Empty

#### Explanation

In, the octal value of 'b' is '\012' but in decimal '10'.
Note
int a ='\012'
int a = 012
All are equal.

### Question 8

Assume that the size of char is 1 byte and negative are stored in 2's complement form,
#include <stdio.h>
int main()
{
char d = 125;
d = d+10;
printf ("%d", d);
return 0;
}

A. 135
B. INF
C. -121
D. -8

#### Explanation

125 is represented as 01111101 in binary and we add 10 i.e. 1010 in binary it becomes 10000111. Now, what does this number represent: Firstly, you should know that char can store numbers only -128 to 127 since the most significant bit is kept for the sign bit. Therefore, 10000111 represents a negative number. To check which number it represents we find the 2's complement of it and get 01111001 which is 121 in the decimal system. Hence, the number 10000111 represents -121.

### Question 9

Predict the output of the following program
#include <stdio.h>
int main( )
{
if (sizeof(int)>-1)
printf ("YES");
else
printf("NO");
return 0;
}

A. YES
B. NO
C. Compiler error
D. Runtime error

#### Explanation

In C, when the integer value is compared with an unsigned one, the integer is encouraged to unsigned. Negative numbers are stored in the form of 2's complement and the unsigned value of the 2's complement form is more than the size of the integer.

### Question 10

Which data type is most suitable for storing a number 65000 in a 32-bit system?
A. signed short
B. unsigned short
C. long
D. int

#### Explanation

The range of short (16-bit) is 0 to 65536. So, 65000 comes in the range from 0 to 65536. That's why unsigned short is the correct answer.

### Question 11

Which of the following is a user-defined data type?
A. Function
B. Pointer
C. Structure
D. All of the above

### Question 12

What is the output of the following code?
#include <stdio.h>
int main()
{
signed char ch;
ch=128;
printf ("%d\n", ch);
return 0;
}

A. 128
B. -128
C. Depends on the compiler
D. None of the mentioned

#### Explanation

The range of the signed character between -128 to 127.

The positive value is from 0 to 127, 127 numbers have been counted, now what comes next after 127 is 128 but if you see it in the circle, then what number has come after 127 i.e. -128.

### Question 13

What is short int the C programming?
A. The basic data type of C
B. Qualifier
C. Short is the qualifier and int is the basic data type
D. All of the above

### Question 14

Which of the following is not a valid declaration in C?
1. signed short a;
2. short a;
3. short int a;
4. unsigned short a;

A. 3 and 4
B. 2
C. 1
D. All are valid

### Question 15

What will be the output when you will execute the following C code?
#include <stdio.h>
int main()
{
printf ("%d\n", sizeof(4.5));
printf ("%d\n", sizeof(80000));
printf ("%d\n", sizeof ('B'));
return 0;
}

A. 4 2 1
B. 8 2 1
C. 4 4 1
D. 8 4 2

#### Explanation

The size of data types in the C programming language depends on the compiler.
In the code block, 4.5 is a double data type.
80000: int
'B': Char
Double is of 8 bytes.
Character is of 4 bytes.
int is 4 bytes.

Recommended Post
Data types in C
Pointers in C

C Data Types (Practice Question) Reviewed by Glory on 08:59 Rating: 5