C Programming MCQ Exam!

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 Chandra
C
Chandra
Community Contributor
Quizzes Created: 1 | Total Attempts: 350
Questions: 10 | Attempts: 350

SettingsSettingsSettings
C Programming MCQ Exam! - Quiz


Are you ready for this C Programming quiz? This quiz answers such questions as what the const feature can be applied to, the correct value to return to the operating system, what are not qualifiers in C, and the usual practice in declaring variables as volatile. Get ready to be tested on complex computer language. This quiz will test you about the C programming language. All the best.


Questions and Answers
  • 1. 

    What are not qualifiers in C? 

    • A.

      Static

    • B.

      Const

    • C.

      Volatile

    • D.

      None of the above

    Correct Answer
    B. Const
    Explanation
    Const is a qualifier in C that is used to declare a variable as a constant, meaning its value cannot be changed once it is assigned. Static and volatile are also qualifiers in C, but they are not included in the list of options given. Therefore, the correct answer is Const.

    Rate this question:

  • 2. 

    Which of the following is not the usual practice in declaring variables as volatile?

    • A.

      Memory-mapped peripheral registers.

    • B.

      Global variables verified by an interrupt service routine.

    • C.

      Static variables.

    • D.

      Global variables accessed by multiple tasks within a multi-threaded application

    Correct Answer
    C. Static variables.
    Explanation
    Static variables are not typically declared as volatile because they are not shared between multiple tasks or threads. Volatile is used to indicate that a variable may be modified by external sources, such as interrupts or other threads, and therefore needs to be accessed directly from memory rather than from a cached value. Static variables, on the other hand, are local to a specific function or module and are not accessed by multiple tasks or threads. Therefore, there is no need to declare them as volatile.

    Rate this question:

  • 3. 

    What is the output?     int main()     {        int i = 2*3 /4+4/ 4+3- 2+ 5 / 3;         printf("%d",i);         } 

    • A.

      8

    • B.

      12

    • C.

      6

    • D.

      None of the above

    Correct Answer
    D. None of the above
    Explanation
    The correct answer is "None of the above". The output of the code is 7. The expression is evaluated from left to right, following the order of operations. First, 2*3 is calculated which equals 6. Then, 6/4 is calculated which equals 1. Next, 4/4 equals 1. Then, 1+1+3-2 equals 3. Finally, 5/3 equals 1. The final result is 3+1 which equals 4. Therefore, the output is 4, not any of the options given.

    Rate this question:

  • 4. 

    What is output? int  main() {           int x[ ] = { 1, 4, 3, 5, 1, 4 };        int *ptr, y;      ptr = x + 4;      y = ptr - x;        printf("%d",y);   }

    • A.

      3

    • B.

      5

    • C.

      4

    • D.

      1

    Correct Answer
    C. 4
    Explanation
    The code initializes an array "x" with values {1, 4, 3, 5, 1, 4}. It then declares a pointer variable "ptr" and an integer variable "y". The pointer "ptr" is assigned the address of the element at index 4 of array "x". The variable "y" is assigned the difference between the address of "ptr" and the address of the first element of array "x". Finally, the value of "y" is printed, which is 4.

    Rate this question:

  • 5. 

    What is the output? int main() {    char *s="Abcat";    printf("%s",s+s[1]-s[3]);      }  

    • A.

      BcatA

    • B.

      Cat

    • C.

      Bcat

    • D.

      Abca

    Correct Answer
    C. Bcat
    Explanation
    The code is using pointer arithmetic to calculate the address of the start of a substring within the string "Abcat". By subtracting the ASCII values of the characters 'c' and 'A' from the address of 's', it is able to find the address of the substring "bcat". The printf statement then prints this substring, resulting in the output "bcat".

    Rate this question:

  • 6. 

    The “const” feature can be applied to?

    • A.

      An array argument

    • B.

      An identifier

    • C.

      An array

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The "const" feature can be applied to an array argument, an identifier, and an array. This means that all three options mentioned in the question can have the "const" feature applied to them.

    Rate this question:

  • 7. 

    What is the correct value to return to the operating system upon the successful?

    • A.

      Null

    • B.

      1

    • C.

      -1

    • D.

      None of the above

    Correct Answer
    D. None of the above
    Explanation
    None of the given options (Null, 1, -1) is a correct value to return to the operating system upon success. The correct value to return would depend on the specific context and requirements of the operating system or program.

    Rate this question:

  • 8. 

    What is the output ?void f(char *);int main(int argc, char** argv){f("123");}void f(char a[]){if(a[1] =='\0') return;f(a+1);f(a+1);printf("%c", a[1]);} 

    • A.

      321

    • B.

      333

    • C.

      332

    • D.

      321

    Correct Answer
    C. 332
    Explanation
    The function f is called with the string "123" as an argument. In the function f, the condition a[1] == '\0' is checked. Since a[1] is not equal to '\0', the function calls itself recursively twice, each time with the argument a+1. This means that the function f is called with "23" and then with "3". When the condition a[1] == '\0' is finally true, the function returns. The printf statement then prints the value of a[1], which is '3'. Therefore, the output is "332".

    Rate this question:

  • 9. 

    What is the output? int main(void)    {          static char food[] ="Yummy";       char *ptr;        ptr = food+strlen(food);        printf("%p",ptr);        return 0; }

    • A.

      Y

    • B.

      Address of y

    • C.

      Unknown value

    • D.

      Run time error

    Correct Answer
    B. Address of y
    Explanation
    The code initializes a static character array named "food" with the value "Yummy". It then declares a character pointer "ptr" and assigns it the address of the last character in the "food" array using the "strlen" function. Finally, it prints the value of "ptr" using the "%p" format specifier, which is the hexadecimal representation of the memory address where the character 'y' is stored. Therefore, the output will be the address of the character 'y'.

    Rate this question:

  • 10. 

    Int main(void){    int x = 2, y, z;    x *= 3 + 2;    x *= y = z = 4;    printf("%d \n", x);    x = y == z;    printf("%d \n", x);    return 0;}

    • A.

      40,1

    • B.

      40,40

    • C.

      40,4

    • D.

      None of the above

    Correct Answer
    A. 40,1
    Explanation
    The code starts by assigning the value 2 to variable x. Then, it multiplies x by the result of 3 + 2, which is 5, so x becomes 10. Next, it multiplies x by the result of y = z = 4, which is also 4. Therefore, x becomes 40. The first printf statement prints the value of x, which is 40. Then, the code assigns the result of y == z to x. Since y and z are both 4, the result is 1 (true). Therefore, the second printf statement prints the value of x, which is 1.

    Rate this question:

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.