C Programming Language Challenge 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 Vivek270657
V
Vivek270657
Community Contributor
Quizzes Created: 1 | Total Attempts: 228
Questions: 10 | Attempts: 228

SettingsSettingsSettings
C Programming Quizzes & Trivia

Did you know that the C programming language is a general procedural computer programming language supporting structured programming? It has discovered maximum use in applications that were formerly encoded in assembly language. This application includes operating systems and different application software for computer experts. C is an imperative procedural language. It was created to be recorded to deliver low-level access to memory and language. Put your knowledge to the test and take this quiz on C programming language.


Questions and Answers
  • 1. 

    main() {             char *ptr1 = “abcdef”;             ptr1 = ptr1 + (strlen(ptr1)-1); printf(“%c”,--*ptr1--); printf(“%c”,--*--ptr1); printf(“%c”,--*(ptr1--)); printf(“%c”,--*(--ptr1)); printf(“%c”,*ptr1);      }

    • A.

      Fedcb

    • B.

      Ecbba

    • C.

      Ecbaa

    • D.

      None of these

    Correct Answer
    C. Ecbaa
    Explanation
    The code initializes a pointer `ptr1` to point to the string "abcdef". The expression `ptr1 = ptr1 + (strlen(ptr1)-1)` moves the pointer to the last character of the string, which is 'f'.

    In the first `printf` statement, `--*ptr1--` decrements the value of 'f' to 'e' and then moves the pointer to the previous character, 'e'.

    In the second `printf` statement, `--*--ptr1` first moves the pointer to the previous character, 'd', and then decrements its value to 'c'.

    In the third `printf` statement, `--*(ptr1--)` decrements the value of 'c' to 'b' and then moves the pointer to the previous character, 'a'.

    In the fourth `printf` statement, `--*(--ptr1)` first moves the pointer to the previous character, 'a', and then decrements its value to 'a'.

    Finally, in the fifth `printf` statement, `*ptr1` simply prints the value of the current character, which is 'a'.

    Therefore, the output of the code is "ecbaa".

    Rate this question:

  • 2. 

    main () {             int a;             a = 3;             e(a); }   void e(int a) {             if(n>0) {                         e(--n);                                                                printf(“%d”,n);                         e(--n);             } }

    • A.

      0123

    • B.

      0120

    • C.

      Error

    • D.

      None of these

    Correct Answer
    B. 0120
    Explanation
    The correct answer is 0120. The code starts with the main function and initializes the variable a with the value 3. Then, it calls the function e with the argument a. In the function e, there is a recursive call to e with the argument n decremented by 1. This means that the function e will be called again with the argument 2. Inside the if statement, there is a printf statement that prints the value of n, which is 2. After that, there is another recursive call to e with the argument n decremented by 1 again, which means the function e will be called with the argument 1. This process continues until n becomes 0. So, the output will be 0120.

    Rate this question:

  • 3. 

    main() {             char a[]=”abcdef”;             char * p = a;             p++;                                                     p++; p[2] = ‘z’; printf(“ %s “,p); }

    • A.

      Abzdef

    • B.

      Zdef

    • C.

      Cdzf

    • D.

      Error

    Correct Answer
    C. Cdzf
    Explanation
    The code initializes a character array "a" with the string "abcdef" and a character pointer "p" pointing to the first element of "a". The code then increments the pointer "p" twice, making it point to the third element of "a". The third element is then assigned the value 'z'. Finally, the code prints the string starting from the pointer "p", which is "cdzf".

    Rate this question:

  • 4. 

    void t1 (char *); main() {             char * p;             p = ”abcdef”;             t1(p); }   void t1(char *q) {             if(*q != ‘d’) {                         putchar(*q);                         t1(q++);             } }

    • A.

      Abc

    • B.

      Aaa

    • C.

      Infinite a

    • D.

      Error

    Correct Answer
    C. Infinite a
    Explanation
    The given code is a recursive function that prints each character of a string until it encounters the character 'd'. In the main function, the string "abcdef" is passed to the t1 function. Inside the t1 function, the condition *q != 'd' is checked. If the condition is true, the character pointed to by q is printed using putchar(*q). Then, the t1 function is called recursively with q incremented by 1 (q++). Since there is no base case or condition to stop the recursion, the function will continue to be called infinitely, printing 'a' repeatedly.

    Rate this question:

  • 5. 

    main () {             printf (“%d”, sizeof (65555));             printf(“%d”,sizeof(65555L));             printf(“%d”,sizeof(6.5F));             printf (“%d”,sizeof (6.5));             printf(“%d”,sizeof(6.5L)); }

    • A.

      2 4 4 4 8

    • B.

      2 4 4 4 10

    • C.

      4 4 4 8 10

    • D.

      None of these

    Correct Answer
    C. 4 4 4 8 10
    Explanation
    The program is using the sizeof operator to determine the size in bytes of different data types. The sizeof operator returns the size of a data type in bytes.

    - sizeof(65555) returns 4 because 65555 is an integer value and the size of an integer is typically 4 bytes.
    - sizeof(65555L) returns 4 because 65555L is a long integer value and the size of a long integer is also typically 4 bytes.
    - sizeof(6.5F) returns 4 because 6.5F is a float value and the size of a float is typically 4 bytes.
    - sizeof(6.5) returns 8 because 6.5 is a double value and the size of a double is typically 8 bytes.
    - sizeof(6.5L) returns 10 because 6.5L is a long double value and the size of a long double is typically 10 bytes.

    Rate this question:

  • 6. 

    main() {             int q, i, j, count;             i=j=0;             q=2;             count = 6;             switch( 3 )             {                         case 0:                                     while ( --count > 0 ) {                                                 case 1:                                                             ++j;                                                 case 2:                                                             ++i;                                                 case 3:  ;                                                 case 4:  ;                                                 case 5:  ;                                     }             }                         printf(“%d”,i);             printf(“%d”,j); }

    • A.

      66

    • B.

      55

    • C.

      00

    • D.

      None of These

    Correct Answer
    B. 55
    Explanation
    The code snippet provided uses a switch statement with the value of 3. Since there is no case for 3, the switch statement does nothing and moves to the next line. The while loop then decrements the count variable until it becomes 0. Inside the while loop, there are cases for 1 and 2 which increment the variables j and i respectively. However, there are no cases for 0, 4, and 5, so these cases do nothing. Therefore, after the while loop, the value of i will be 0 and the value of j will be 2. The correct answer is 55, which is the value of j.

    Rate this question:

  • 7. 

    Which of the following does not have an unary operator?

    • A.

      -7

    • B.

      ++j

    • C.

      J

    • D.

      !i

    Correct Answer
    C. J
    Explanation
    The given options include -7, ++j, j, and !i. The unary operator is an operator that operates on a single operand. In this case, the unary operator is the exclamation mark (!) which is used for logical negation. It is applied to the operand i in the expression !i. However, the variable j does not have any unary operator applied to it, making it the correct answer.

    Rate this question:

  • 8. 

    A union consists of a number of elements that

    • A.

      All occupy the same space in memory

    • B.

      Must be structure

    • C.

      Are grouped next to each other in memory

    • D.

      All have the same type

    Correct Answer
    A. All occupy the same space in memory
    Explanation
    In a union, all the elements occupy the same space in memory. This means that only one element of the union can be stored at a time, and accessing one element may overwrite the value of another element. This is different from a structure, where each element has its own separate space in memory. The elements in a union can have different types, but they all share the same memory space.

    Rate this question:

  • 9. 

    The int type of constraints are whole numbers in the range

    • A.

      -23677 to 23678

    • B.

      -32768 to 32767

    • C.

      -32767 to 32768

    • D.

      -32864 to 32864

    Correct Answer
    B. -32768 to 32767
    Explanation
    The correct answer is -32768 to 32767. This range represents the valid values for the int data type in programming. The int type is used to store whole numbers, and this range ensures that the values fall within the limits of the data type. Values below -32768 or above 32767 would result in an overflow or underflow, potentially causing unexpected behavior in the program. Therefore, the range of -32768 to 32767 is the correct answer for the int type of constraints.

    Rate this question:

  • 10. 

    If the variables i,j and k are assigned the values 5,3 and 2 respectively, then the expression i=j+(k++ =6)+7;

    • A.

      Assigns a value 16 to i

    • B.

      Assigns a value 18 to i

    • C.

      Assigns a value 19 to i

    • D.

      Gives an error message

    Correct Answer
    D. Gives an error message
    Explanation
    The expression i=j+(k++ =6)+7; gives an error message because the assignment operator (=) is used inside the parentheses. The assignment operator is not allowed in an expression because it does not return a value. Therefore, the expression is not valid and cannot be evaluated.

    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
  • Feb 22, 2011
    Quiz Created by
    Vivek270657
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.