C Skills Test: 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 Pradeep Surasura
P
Pradeep Surasura
Community Contributor
Quizzes Created: 1 | Total Attempts: 363
Questions: 21 | Attempts: 363

SettingsSettingsSettings
C Skills Test: Trivia Quiz! - Quiz

.


Questions and Answers
  • 1. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> struct marks{ int p:3; int c:3; int m:2; }; int main(){ struct marks s={2,-6,5}; printf("%d %d %d",s.p,s.c,s.m); return 0; }

    • A.

      2 -6 5

    • B.

      2 -6 1

    • C.

      2 2 1

    • D.

      Compiler error

    • E.

      None of these

    Correct Answer
    C. 2 2 1
    Explanation
    The code defines a structure called "marks" with three members: p, c, and m. These members are defined using bit fields, with p and c having 3 bits each and m having 2 bits.

    In the main function, a variable of type "marks" is declared and initialized with values 2, -6, and 5 for p, c, and m respectively.

    When the code is executed, the printf statement prints the values of s.p, s.c, and s.m, which are 2, 2, and 1 respectively.

    Therefore, the output of the code will be "2 2 1".

    Rate this question:

  • 2. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int huge*p=(int huge*)0XC0563331; int huge*q=(int huge*)0xC2551341; *p=200; printf("%d",*q); return 0; }

    • A.

      0

    • B.

      Garbage value

    • C.

      Null

    • D.

      200

    • E.

      Compiler error

    Correct Answer
    D. 200
    Explanation
    The code declares two pointers, p and q, of type int huge. The values assigned to these pointers are memory addresses in hexadecimal format. The value assigned to p is 0XC0563331 and the value assigned to q is 0xC2551341. Then, the code assigns the value 200 to the memory location pointed to by p. Finally, the code prints the value at the memory location pointed to by q, which is 200. Therefore, the output of the code will be 200.

    Rate this question:

  • 3. 

    What will be output if you will compile and execute the following c code? void main(){ if(printf("cquestionbank")) printf("I know c"); else printf("I know c++"); }

    • A.

      I know c

    • B.

      I know c++

    • C.

      CquestionbankI know c

    • D.

      CquestionbankI know c++

    • E.

      Compiler error

    Correct Answer
    C. CquestionbankI know c
    Explanation
    The code will output "cquestionbankI know c". This is because the printf function returns the number of characters printed. In this case, the string "cquestionbank" has 12 characters, so the if statement evaluates to true. Therefore, the first printf statement will be executed and "cquestionbank" will be printed. After that, the second printf statement "I know c" will also be executed.

    Rate this question:

  • 4. 

    What will be output if you will compile and execute the following c code? #define call(x) #x void main(){    printf("%s",call(c/c++)); }

    • A.

      C

    • B.

      C++

    • C.

      #c/c++

    • D.

      C/c++

    • E.

      Compiler Error

    Correct Answer
    D. C/c++
    Explanation
    The code snippet defines a macro `call(x)` which takes an argument `x` and converts it into a string literal using the `#` operator. The `main()` function then calls `printf()` to print the result of `call(c/c++)`. Since `c/c++` is passed as an argument to `call()`, it will be converted into a string literal `"c/c++"`. Therefore, the output will be `c/c++`.

    Rate this question:

  • 5. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int i; float a=5.2; char *ptr; ptr=(char *)&a; for(i=0;i<=3;i++) printf("%d ",*ptr++); return 0; }

    • A.

      0 0 0 0

    • B.

      Garbage Garbage Garbage Garbage

    • C.

      102 56 -80 32

    • D.

      102 102 -90 64

    • E.

      Compiler error

    Correct Answer
    D. 102 102 -90 64
    Explanation
    The code is trying to print the individual bytes of the float variable 'a'. The pointer 'ptr' is assigned the address of 'a' casted to a char pointer. In the for loop, the value pointed to by 'ptr' is printed and then the pointer is incremented. Since 'a' is a float, it occupies 4 bytes in memory. Therefore, the loop runs 4 times. The output is the decimal representation of the individual bytes of 'a' in little-endian format. So, the output is 102 102 -90 64.

    Rate this question:

  • 6. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int i; double a=5.2; char *ptr; ptr=(char *)&a; for(i=0;i<=7;i++) printf("%d ",*ptr++); return 0; }

    • A.

      -51 -52 -52 -52 -52 -52 20 64

    • B.

      51 52 52 52 52 52 20 64

    • C.

      Eight garbage values

    • D.

      Compiler error

    • E.

      None of these

    Correct Answer
    A. -51 -52 -52 -52 -52 -52 20 64
    Explanation
    The given code declares a variable 'a' of type double and initializes it with the value 5.2. It also declares a pointer variable 'ptr' of type char. The code then assigns the address of 'a' to 'ptr' by typecasting it to a char pointer.

    In the for loop, the code prints the integer value at each memory location pointed to by 'ptr' by dereferencing it and incrementing 'ptr' after each iteration. Since 'ptr' is a char pointer, it points to 1 byte of memory.

    The output is -51 -52 -52 -52 -52 -52 20 64 because the individual bytes of the double value 5.2 are printed as integers.

    Rate this question:

  • 7. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ printf("%s","c" "question" "bank"); return 0; }

    • A.

      C question bank

    • B.

      C

    • C.

      Bank

    • D.

      Cquestionbank

    • E.

      Compiler error

    Correct Answer
    D. Cquestionbank
    Explanation
    The given C code will compile and execute without any errors. The printf statement will print the concatenated string "cquestionbank" as the output.

    Rate this question:

  • 8. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ char *str="c-pointer"; printf("%*.*s",10,7,str); return 0; }

    • A.

      C-pointer

    • B.

      C-pointerc-pointer

    • C.

      C-pointc-point

    • D.

      Cpointer null null

    • E.

      C-point

    Correct Answer
    E. C-point
    Explanation
    The code declares a character pointer variable "str" and assigns it the address of the string "c-pointer". The printf function is then used to print a formatted string. The format specifier "%*.*s" is used to specify the width and precision of the string to be printed. In this case, the width is set to 10 and the precision is set to 7. Since the string "c-pointer" has a length of 9, it will be printed as "c-point" with 3 spaces added before it to reach the width of 10.

    Rate this question:

  • 9. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int a=-12; a=a>>3; printf("%d",a); return 0; }

    • A.

      -4

    • B.

      -3

    • C.

      -2

    • D.

      -96

    • E.

      Compiler error

    Correct Answer
    C. -2
    Explanation
    The given C code declares a variable 'a' and assigns it the value -12. Then, the value of 'a' is right-shifted by 3 bits using the '>>' operator. This means that the bits of 'a' are shifted 3 positions to the right. Since 'a' is a signed integer, the sign bit is preserved during right shifting. Therefore, the value of 'a' after the right shift will be -2. Finally, the value of 'a' is printed using the printf() function, resulting in the output -2.

    Rate this question:

  • 10. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> #include <string.h> int main(){ printf("%d %d",sizeof("string"),strlen("string")); return 0; }

    • A.

      6 6

    • B.

      7 7

    • C.

      6 7

    • D.

      7 6

    • E.

      None of these

    Correct Answer
    D. 7 6
    Explanation
    The output of the code will be "7 6". The sizeof() function in C returns the size of the data type or variable in bytes. In this case, the size of the string "string" is 7 bytes because it includes the null character '\0' at the end. The strlen() function returns the length of the string, excluding the null character, which is 6 in this case. Therefore, the output will be "7 6".

    Rate this question:

  • 11. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ static main; int x; x=call(main); printf("%d ",x); return 0; } int call(int address){ address++; return address; }

    • A.

      0

    • B.

      1

    • C.

      Garbage value

    • D.

      Compiler error

    • E.

      None of these

    Correct Answer
    B. 1
    Explanation
    The code defines a static variable named "main" inside the main function, which is not allowed in C. Static variables should be declared outside of any function. Therefore, the code will result in a compiler error.

    Rate this question:

  • 12. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int a,b; a=1,3,15; b=(2,4,6); printf("%d ",a+b); return 0; }

    • A.

      3

    • B.

      21

    • C.

      17

    • D.

      7

    • E.

      Compiler error

    Correct Answer
    D. 7
    Explanation
    The code assigns the value 1 to variable a and the value 6 to variable b. The printf statement then adds the values of a and b, resulting in 7.

    Rate this question:

  • 13. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int extern x; int main() printf("%d",x); x=2; return 0; } int x=23;

    • A.

      0

    • B.

      2

    • C.

      23

    • D.

      Compiler error

    • E.

      None of these

    Correct Answer
    C. 23
    Explanation
    The code starts by declaring an external variable "x" using the "extern" keyword. In the main function, it prints the value of "x", which is 23. After that, it assigns the value 2 to "x". However, since the assignment statement is outside of any function, it will not be executed. Therefore, the output will be 23.

    Rate this question:

  • 14. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int i=0; if(i==0){ i=((5,(i=3)),i=1); printf("%d",i); } Else printf("equal"); }

    • A.

      5

    • B.

      3

    • C.

      1

    • D.

      Equal

    • E.

      None of above

    Correct Answer
    C. 1
    Explanation
    The code initializes the variable i to 0. The if statement checks if i is equal to 0. Since i is indeed equal to 0, the code inside the if statement is executed. The expression ((5,(i=3)),i=1) is evaluated. The comma operator evaluates the expressions from left to right and returns the value of the rightmost expression. In this case, the expression (i=3) assigns the value 3 to i and returns 3. Then, the expression ((5,3),i=1) is evaluated. The comma operator again evaluates the expressions from left to right and returns the value of the rightmost expression. In this case, the expression (5,3) returns 3. Finally, the expression ((3,3),1) is evaluated. The comma operator again evaluates the expressions from left to right and returns the value of the rightmost expression. In this case, the expression (3,3) returns 3. Therefore, the value of i is set to 3. The printf statement then outputs the value of i, which is 3.

    Rate this question:

  • 15. 

    What will be output if you will compile and execute the following c code? int main(){ int a=25; printf("%o %x",a,a); return 0; }

    • A.

      25 25

    • B.

      025 0x25

    • C.

      12 42

    • D.

      31 19

    • E.

      None of these

    Correct Answer
    D. 31 19
    Explanation
    The code is using the format specifiers "%o" and "%x" in the printf function.

    "%o" is used to print the value of 'a' in octal format, which is 31 in decimal.

    "%x" is used to print the value of 'a' in hexadecimal format, which is 19 in decimal.

    Therefore, the output of the code will be "31 19".

    Rate this question:

  • 16. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> #define message "union is\ power of c" int main(){ printf("%s",message); return 0; }

    • A.

      Union is power of c

    • B.

      Union ispower of c

    • C.

      Union is Power of c

    • D.

      Compiler error

    • E.

      None of these

    Correct Answer
    B. Union ispower of c
    Explanation
    The code will output "union ispower of c" because the #define statement defines the macro "message" as "union is\power of c". The backslash (\) is used to continue the definition on the next line. Therefore, when the printf statement is executed, it will print the value of the "message" macro, which is "union ispower of c".

    Rate this question:

  • 17. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ int i=10; static int x=i; if(x==i) printf("Equal"); else if(x>i) printf("Greater than"); else printf("Less than"); return 0; }

    • A.

      Equal

    • B.

      Greater than

    • C.

      Less than

    • D.

      Compiler error

    • E.

      None of above

    Correct Answer
    D. Compiler error
    Explanation
    The code will result in a compiler error because the initialization of the static variable "x" with "i" is not allowed. The initialization of a static variable must be a constant expression, but "i" is not a constant.

    Rate this question:

  • 18. 

    What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){ printf("%s",__DATE__); return 0; }

    • A.

      Current system date

    • B.

      Current system date with time

    • C.

      Null

    • D.

      Compiler error

    • E.

      None of these

    Correct Answer
    A. Current system date
    Explanation
    The given C code will output the current system date when compiled and executed. The __DATE__ macro in C returns a string representation of the current system date.

    Rate this question:

  • 19. 

    What will be output if you will compile and execute the following c code? #include void start(); void end(); #pragma startup start #pragma exit end int static i; int main(){ printf("\nmain function: %d",++i); return 0; } void start(){ printf("\nstart function: %d",++i); } void end(){ printf("\nend function: %d",++i); }

    • A.

      Main function: 2 start function: 1 end function:3

    • B.

      Start function: 1 main function: 2 end function:3

    • C.

      Main function: 2 end function:3 start function: 1

    • D.

      Compiler error

    • E.

      None of these

    Correct Answer
    B. Start function: 1 main function: 2 end function:3
    Explanation
    The code includes two functions, start() and end(), which are declared as startup and exit functions respectively using the #pragma directive. These functions are executed before the main() function is called and after it returns.

    In the main() function, the value of the static variable i is incremented by 1 and then printed. The output will be "main function: 2".

    In the start() function, the value of i is again incremented by 1 and then printed. The output will be "start function: 1".

    In the end() function, the value of i is once again incremented by 1 and then printed. The output will be "end function: 3".

    Therefore, the correct answer is "start function: 1 main function: 2 end function:3".

    Rate this question:

  • 20. 

    What will be output of the following c program? #include<stdio.h> int main(){ int goto=5; printf("%d",goto); return 0; }

    • A.

      5

    • B.

      **

    • C.

      ****

    • D.

      Compilation error

    • E.

      None of these

    • F.

      None of these

    Correct Answer
    D. Compilation error
    Explanation
    The program will produce a compilation error. The error occurs because "goto" is a reserved keyword in C and cannot be used as a variable name.

    Rate this question:

  • 21. 

    What will be output of the following c program? #include<stdio.h> int main(){ int class=150; int public=25; int private=30; class = class >> private - public; printf("%d",class); return 0; }

    • A.

      1

    • B.

      2

    • C.

      4

    • D.

      Compilation error

    • E.

      None of these

    Correct Answer
    C. 4
    Explanation
    This program will output the value 4. The program declares three variables: class, public, and private. Since class is a keyword in C, it cannot be used as a variable name. However, the program compiles because the variable name is not used in the program. The expression `class = class >> private - public;` performs a right shift operation on the value of class by the difference between private and public. The result of this operation is then assigned back to the class variable. In this case, the difference between private and public is 5, so the right shift operation by 5 bits effectively divides the value of class by 32. Since the initial value of class is 150, dividing it by 32 gives a result of 4. Therefore, the program will print 4 as the output.

    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
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 09, 2018
    Quiz Created by
    Pradeep Surasura
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.