Data Types Trivia Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Jawahar Ganesh
J
Jawahar Ganesh
Community Contributor
Quizzes Created: 1 | Total Attempts: 170
| Attempts: 170 | Questions: 9
Please wait...
Question 1 / 9
0 %
0/100
Score 0/100
1. Which of the following is not a valid declaration in C?
1. short int x; 
2. signed short x; 
3. short x; 
4. unsigned short x; 

Explanation

All of the given options are valid declarations in C. Option 1 declares a short integer variable named x. Option 2 declares a signed short integer variable named x. Option 3 declares a variable named x of type short. Option 4 declares an unsigned short integer variable named x. Therefore, all the given options are valid declarations in C.

Submit
Please wait...
About This Quiz
Data Types Trivia Quiz - Quiz

This Data types Trivia quiz assesses understanding of C programming data types, focusing on variable declarations, pointer usage, and output predictions. It's ideal for learners enhancing their programming skills and understanding of fundamental computer science concepts.

Personalize your quiz and earn a certificate with your name on it!
2. Predict the output of following program. Assume that the numbers are stored in 2's complement form.
#include<stdio.h>   int  main()   {      unsigned int x = -1;      int y = ~0;      if(x == y)         printf("same");      else         printf("not same");      return 0;   }

Explanation

The program initializes an unsigned integer variable "x" with the value -1. In 2's complement form, -1 is represented as a sequence of all 1's. The program also initializes an integer variable "y" with the bitwise complement of 0, which is also a sequence of all 1's. In the if statement, it checks if "x" is equal to "y". Since both "x" and "y" have the same value of all 1's, the condition is true and the program prints "same". Therefore, the output of the program is "Same".

Submit
3. In C, sizes of an integer and a pointer must be same.

Explanation

In C, the sizes of an integer and a pointer are not required to be the same. The size of an integer is typically 4 bytes, while the size of a pointer can vary depending on the system architecture. On a 32-bit system, the size of a pointer is usually 4 bytes, while on a 64-bit system, it is typically 8 bytes. Therefore, the statement that the sizes of an integer and a pointer must be the same is false.

Submit
4. Predict the output
#include <stdio.h> int main() {    float c = 5.0;    printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32);    return 0; }

Explanation

The code is calculating the temperature in Fahrenheit using the formula (9/5)*c + 32, where c is the temperature in Celsius. In this case, c is initialized to 5.0. The expression (9/5)*c + 32 is evaluated as (1)*5.0 + 32, which results in 37.00. Therefore, the output is "Temperature in Fahrenheit is 37.00".

Submit
5. Output of following program?
#include<stdio.h> int main() {     float x = 0.1;     if ( x == 0.1 )         printf("IF");     else if (x == 0.1f)         printf("ELSE IF");     else         printf("ELSE"); }

Explanation

The output of the program is "ELSE IF". This is because the variable x is declared as a float and assigned the value 0.1. However, the if statement checks if x is equal to 0.1, which is a double precision value. Since the float value 0.1 is not exactly equal to the double value 0.1, the condition in the if statement evaluates to false. The else if statement checks if x is equal to 0.1f, which is the float value of 0.1. Since x is equal to 0.1, the condition in the else if statement evaluates to true and the corresponding printf statement is executed, resulting in the output "ELSE IF".

Submit
6. Output?
int main() {     void *vptr, v;     v = 0;     vptr = &v;     printf("%v", *vptr);     getchar();     return 0; }

Explanation

The given code will result in a compiler error. This is because the format specifier used in the printf statement is incorrect. The correct format specifier for printing a void pointer is "%p", not "%v". Since the code is trying to print the value of a void pointer using an incorrect format specifier, it will result in a compiler error.

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

Explanation

In this code, the variable 'c' is declared as a char with an initial value of 125. Then, 'c' is assigned a new value by adding 10 to its current value. However, since the range of a char in 2's complement form is -128 to 127, adding 10 to 125 will result in an overflow. This means that the value will wrap around to the minimum value in the range, which is -128. Therefore, the final value of 'c' is -121.

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

Explanation

The program is using the format specifier "%d" in the printf() function to print the value of the variable 'a'. The variable 'a' is assigned the character '\012', which is an octal representation of the decimal value 10. Therefore, the output of the program will be 10.

Submit
9. #include <stdio.h> int main() {     if (sizeof(int) > -1)         printf("Yes");     else         printf("No");     return 0; } 

Explanation

The code checks if the size of an integer is greater than -1. Since the size of an integer is always a positive value, the condition will always be true. Therefore, "Yes" will never be printed and "No" will always be printed.

Submit
View My Results

Quiz Review Timeline (Updated): Nov 1, 2024 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Nov 01, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 24, 2014
    Quiz Created by
    Jawahar Ganesh
Cancel
  • All
    All (9)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following is not a valid declaration in C?1. short int...
Predict the output of following program. Assume that the numbers are...
In C, sizes of an integer and a pointer must be same.
Predict the output#include <stdio.h> int...
Output of following program?#include<stdio.h> int...
Output?int main() {     void *vptr,...
Assume that the size of char is 1 byte and negatives are stored in...
Predict the output of following C program#include...
#include <stdio.h> int...
Alert!

Advertisement