C Language Programming 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 Dhanashree Awati
D
Dhanashree Awati
Community Contributor
Quizzes Created: 1 | Total Attempts: 251
Questions: 20 | Attempts: 252

SettingsSettingsSettings
C Language Programming Test! Trivia Quiz - Quiz


What do you know about C language programming? There are so many different types of computer languages, and it can be a daunting task to know which is which. C language is a structure-oriented programming language, and it is within the middle level of programming. The Windows program is written in C language, and there are some basic rules for success with this language. Take this test and find out if you are successful in learning about C language programming.


Questions and Answers
  • 1. 

    Which of the following shows the correct hierarchy of arithmetic operations in C? 

    • A.

      / + * –

    • B.

      * – / +

    • C.

      + – / *

    • D.

      * / + –

    Correct Answer
    D. * / + –
    Explanation
    The correct hierarchy of arithmetic operations in C is as follows: first, multiplication (*), then division (/), then addition (+), and finally subtraction (–). This order of operations is commonly known as "PEMDAS" or "BODMAS" and is used to determine the sequence in which arithmetic operations should be performed in an expression.

    Rate this question:

  • 2. 

    What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of the array?

    • A.

      The element will be set to 0.

    • B.

      The compiler would report an error.

    • C.

      The program may crash if some important data gets overwritten.

    • D.

      The array size would appropriately grow.

    Correct Answer
    C. The program may crash if some important data gets overwritten.
    Explanation
    If a value is assigned to an array element whose subscript exceeds the size of the array, it means that the program is accessing memory beyond the allocated space for the array. This can result in overwriting important data that is stored in adjacent memory locations. As a result, the program may crash or produce unexpected behavior. Therefore, the correct answer is that the program may crash if some important data gets overwritten.

    Rate this question:

  • 3. 

    int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What value does testarray[2][1][0] in the sample code above contain?

    • A.

      11

    • B.

      7

    • C.

      5

    • D.

      9

    Correct Answer
    A. 11
    Explanation
    The value in testarray[2][1][0] is 11. This is because the array is a three-dimensional array with dimensions [3][2][2]. The first index represents the outermost dimension, the second index represents the middle dimension, and the third index represents the innermost dimension. In this case, testarray[2][1][0] refers to the element in the third group, second row, and first column of the array, which is 11.

    Rate this question:

  • 4. 

    What will be the output of the following statements? int i = 3; printf(“%d%d”,i,i++);                          

    • A.

      34

    • B.

      43

    • C.

      44

    • D.

      33

    Correct Answer
    B. 43
    Explanation
    The output of the given statements will be 43. The printf statement uses the format specifier "%d%d" to print two integers. The first occurrence of "i" in the printf statement will print the current value of "i" which is 3. The second occurrence of "i" in the printf statement is followed by the post-increment operator "++" which increments the value of "i" to 4. However, since the post-increment operator is used, the value of "i" is incremented after it is printed. Therefore, the second occurrence of "i" in the printf statement will also print 3. Hence, the output will be "43".

    Rate this question:

  • 5. 

    With what do you replace the? long factorial (long x) { ???? return x * factorial(x – 1); }

    • A.

      If (x == 0) return 0;

    • B.

      Return 1;

    • C.

      If (x >= 2) return 2;

    • D.

      If (x <= 1) return 1;

    Correct Answer
    D. If (x <= 1) return 1;
    Explanation
    The correct answer is "if (x

    Rate this question:

  • 6. 

    What would be the output of the following program? #include main() { char str[]=”S\065AB”; printf(“\n%d”, sizeof(str)); }

    • A.

      7

    • B.

      6

    • C.

      5

    • D.

      Error

    Correct Answer
    B. 6
    Explanation
    The program declares a character array named "str" and initializes it with the string "S\065AB". The sizeof() function is used to determine the size of the array in bytes. Since the array has 6 characters (including the null terminator), the output of the program would be 6.

    Rate this question:

  • 7. 

    What will be the output? int main() {             char *str="includehelp";             printf("%s",str+7);             return 0; }

    • A.

      Help     

    • B.

                  includehelp

    • C.

      Ehelp

    • D.

      None of these

    Correct Answer
    A. Help     
    Explanation
    The correct answer is "help". In this program, the pointer variable "str" is pointing to the string "includehelp". When we use the expression "str+7" in the printf statement, it means that we are starting from the 7th character of the string. So, the output will be "help".

    Rate this question:

  • 8. 

    What will be the output in the given input?     int main() { int n,i=0; while(scanf("%d",&n)==1) { printf("END\n"); } return 0; }

    • A.

      Runtime_error and Compile time error

    • B.

      Compile time error and Runtime_error

    • C.

      Syntax error and Syntax error

    • D.

      No output and END

    Correct Answer
    D. No output and END
    Explanation
    The given code is a simple program that reads integers from the input until it encounters an invalid input. In this case, the program uses the scanf function to read an integer into the variable n. If the scanf function successfully reads an integer, it returns 1, and the while loop continues. Inside the loop, the program prints "END" followed by a line break. However, since there is no input provided in the given code, the scanf function will not be able to read any integers, and the while loop will not execute. Therefore, there will be no output and the program will terminate.

    Rate this question:

  • 9. 

    What will be the output of following program (on 32 bit compiler)? #include int main() {     int x=65;     const unsigned char c=(int)x;         printf("%c\n",c);     return 0; }

    • A.

      65.00

    • B.

      65

    • C.

      A

    • D.

      Error

    Correct Answer
    C. A
    Explanation
    The program will output the character 'A'. The variable 'x' is assigned the value 65, which is the ASCII value for the character 'A'. The variable 'c' is then casted to an unsigned char, which means it will only store the lowest 8 bits of the value. When the variable 'c' is printed using the '%c' format specifier, it will interpret the value as a character and print 'A'.

    Rate this question:

  • 10. 

    Which header file should be included to use functions like malloc() and calloc()?

    • A.

      Memory.h

    • B.

      Stdlib.h

    • C.

      String.h

    • D.

      Dos.h

    Correct Answer
    B. Stdlib.h
    Explanation
    The correct answer is stdlib.h. This header file should be included to use functions like malloc() and calloc().

    Rate this question:

  • 11. 

    What is (void*)0?

    • A.

      Representation of NULL pointer

    • B.

      Representation of void pointer

    • C.

      Error

    • D.

      None of above

    Correct Answer
    A. Representation of NULL pointer
    Explanation
    (void*)0 is a representation of the NULL pointer. In C and C++, NULL is typically defined as (void*)0, indicating a pointer that does not point to any valid memory location. This is often used to initialize pointers or to indicate that a pointer does not currently refer to any object.

    Rate this question:

  • 12. 

    How many bytes are occupied by near, far and huge pointers (DOS)?

    • A.

      Near=2 far=4 huge=4

    • B.

      Near=4 far=8 huge=8

    • C.

      Near=2 far=4 huge=8

    • D.

      Near=4 far=4 huge=8

    Correct Answer
    A. Near=2 far=4 huge=4
    Explanation
    Near pointers in DOS occupy 2 bytes of memory, while far and huge pointers occupy 4 bytes of memory each. This is because near pointers are used for accessing data within the same segment, so they only need to store the offset. Far and huge pointers, on the other hand, are used for accessing data in different segments, so they need to store both the segment and the offset. Therefore, they require more memory space.

    Rate this question:

  • 13. 

    What would be the equivalent pointer expression for referring the array element a[i][j][k][l]                                                                

    • A.

      ((((a+i)+j)+k)+l)

    • B.

      *(*(*(*(a+i)+j)+k)+l)

    • C.

      (((a+i)+j)+k+l)

    • D.

      ((a+i)+j+k+l)

    Correct Answer
    B. *(*(*(*(a+i)+j)+k)+l)
    Explanation
    The correct answer is `*(*(*(*(a+i)+j)+k)+l)`. This expression is used to refer to the array element `a[i][j][k][l]`. The expression `a+i` is used to access the `i`th element of the array `a`, then `*(a+i)+j` is used to access the `j`th element of the `i`th element, and so on until `l`. Finally, `*(*(*(*(a+i)+j)+k)+l)` is used to dereference the pointer and obtain the value of the desired array element.

    Rate this question:

  • 14. 

    The following program reports an error on compilation.        #include int main() {     float i=10, *j;     void *k;     k=&i;     j=k;     printf("%f\n", *j);     return 0; }

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The program will report an error on compilation because a void pointer cannot be directly assigned to a float pointer without a typecast. In this program, the void pointer 'k' is assigned the address of the float variable 'i', but when trying to assign 'k' to the float pointer 'j', a typecast is required. Without the typecast, the program will not compile.

    Rate this question:

  • 15. 

    Point out the compile time error in the program given below. #include int main() {     int *x;     *x=100;     return 0; }

    • A.

      Error: invalid assignment for x

    • B.

      Error: suspicious pointer conversion

    • C.

      No error

    • D.

      None of above

    Correct Answer
    C. No error
    Explanation
    The program has a compile-time error in the line "*x=100;". This is because the pointer variable "x" has not been assigned any memory location using the "new" keyword or by pointing it to an existing variable. Therefore, when trying to assign a value to the memory location pointed by "x", it results in an invalid assignment error. However, the given answer "No error" is incorrect as there is indeed a compile-time error in the program.

    Rate this question:

  • 16. 

    How many times the below loop will run? main() {             int i;             i=0;             do             {                         --i;                         printf("%d",i);                         i++;             }             while(i>=0);

    • A.

      1

    • B.

      Infinite

    • C.

      0

    • D.

      Compilation Error  

    Correct Answer
    B. Infinite
    Explanation
    The loop will run infinitely because the condition in the do-while loop is i>=0, and inside the loop, i is decremented and then incremented. This means that i will always remain greater than or equal to 0, and the loop will continue to execute indefinitely.

    Rate this question:

  • 17. 

    What will be the output                                                     main() {             int i, j, *ptr, *ptr1;             i = 10;             j = 10;             ptr = &i;             ptr1 = &j;             if(ptr == ptr1)             {                         printf("True");             }             else             {                         printf("False");             } }

    • A.

      True

    • B.

      False

    • C.

      Syntax ErrorĀ 

    • D.

      Run time Error

    Correct Answer
    B. False
    Explanation
    The output of the given code will be "False". This is because the variables "i" and "j" are assigned different values (both 10) and the pointers "ptr" and "ptr1" are assigned the addresses of these variables respectively. Since the addresses of "i" and "j" are different, the condition "ptr == ptr1" will evaluate to false, and the "else" block will be executed, resulting in the output "False".

    Rate this question:

  • 18. 

    Which of the statements is correct about the program?  #include int main() { int i=10; int *j=&i; return 0; }

    • A.

      J and i are pointers to an int

    • B.

      I is a pointer to an int and stores address of j

    • C.

      J is a pointer to an int and stores address of i

    • D.

      J is a pointer to a pointer to an int and stores address of i

    Correct Answer
    C. J is a pointer to an int and stores address of i
    Explanation
    In the given program, the variable "j" is declared as a pointer to an int using the "*" symbol. It is then assigned the address of the variable "i" using the "&" symbol. This means that "j" is a pointer to an int and it stores the address of "i".

    Rate this question:

  • 19. 

    What will be the output                                                      main() {             float me = 1.1;             double you = 1.1;             if(me==you) printf("I love U"); else                         printf("I hate U"); }  

    • A.

      I Love U

    • B.

      Love You

    • C.

      I hate U

    • D.

      I Hate You

    Correct Answer
    C. I hate U
    Explanation
    The output will be "I hate U" because the float variable "me" and the double variable "you" are not exactly equal even though their values are both 1.1. This is due to the way floating-point numbers are stored and compared in computer systems. Therefore, the condition in the if statement will evaluate to false and the program will execute the else statement, resulting in the "I hate U" message being printed.

    Rate this question:

  • 20. 

    Which of the following function calculates the square of 'x' in C?  

    • A.

      Sqr(x)

    • B.

      Pow(2, x)

    • C.

      Pow(x, 2)

    • D.

      Power(2, x)

    Correct Answer
    C. Pow(x, 2)
    Explanation
    The pow(x, 2) function calculates the square of 'x' in C. The pow function is a mathematical function in C that is used to calculate the power of a number. In this case, the pow(x, 2) function is used to calculate the square of 'x' by raising 'x' to the power of 2.

    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
  • Sep 28, 2019
    Quiz Created by
    Dhanashree Awati
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.