Data Types Trivia Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Jawahar Ganesh
J
Jawahar Ganesh
Community Contributor
Quizzes Created: 1 | Total Attempts: 163
Questions: 9 | Attempts: 163

SettingsSettingsSettings
Data Types Trivia Quiz - Quiz


Questions and Answers
  • 1. 

    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;   }

    • A.

      Same

    • B.

      Not Same

    Correct Answer
    A. Same
    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".

    Rate this question:

  • 2. 

    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; 

    • A.

      3 and 4

    • B.

      2

    • C.

      1

    • D.

      All are valid

    Correct Answer
    D. All are valid
    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.

    Rate this question:

  • 3. 

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

    • A.

      Temperature in Fahrenheit is 41.00

    • B.

      Temperature in Fahrenheit is 37.00

    • C.

      Temperature in Fahrenheit is 0.00

    • D.

      Compiler Error

    Correct Answer
    B. Temperature in Fahrenheit is 37.00
    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".

    Rate this question:

  • 4. 

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

    • A.

      Compiler error

    • B.

      12

    • C.

      10

    • D.

      Empty

    Correct Answer
    C. 10
    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.

    Rate this question:

  • 5. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    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.

    Rate this question:

  • 6. 

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

    • A.

      0

    • B.

      Compiler error

    • C.

      Garbage value

    Correct Answer
    B. Compiler error
    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.

    Rate this question:

  • 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; }

    • A.

      135

    • B.

      +INF

    • C.

      -121

    • D.

      -8

    Correct Answer
    C. -121
    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.

    Rate this question:

  • 8. 

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

    • A.

      Yes

    • B.

      No

    • C.

      Compiler error

    • D.

      Run time error

    Correct Answer
    B. No
    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.

    Rate this question:

  • 9. 

    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"); }

    • A.

      ELSE IF

    • B.

      IF

    • C.

      ELSE

    Correct Answer
    A. ELSE IF
    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".

    Rate this question:

Quiz Review Timeline +

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.