C Programming Skills Test: 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 Shrenya Mathur
S
Shrenya Mathur
Community Contributor
Quizzes Created: 2 | Total Attempts: 859
Questions: 10 | Attempts: 509

SettingsSettingsSettings
C Programming Skills Test: Quiz! - Quiz

.


Questions and Answers
  • 1. 

    Find Error/Output in following code: How many times "Placement Question" will print. int main()  {   int x;   for(x=-1; x<=10; x++)   {     if(x < 5)       continue;     else       break;     printf("Placement Question");   }    return 0; }

    • A.

      Infinite Time

    • B.

      11 Times

    • C.

      0 Times

    • D.

      10 Times 

    Correct Answer
    C. 0 Times
    Explanation
    The code will not print "Placement Question" any times. This is because the loop condition is x

    Rate this question:

  • 2. 

    Find Error/Output in following code: int main() {   int a = 10, b = 25;   a = b++ + a++;   b = ++b + ++a;   printf("%d %d n", a, b); } 

    • A.

      36 64

    • B.

      35 62

    • C.

      36 63

    • D.

      20 28

    Correct Answer
    A. 36 64
    Explanation
    The format specifier in the printf statement is incorrect. It should be %d %d\n instead of %d %d n. The correct specifier for a newline character is \n, not n.
    The order of evaluation of the expressions involving post-increment (a++ and b++) and pre-increment (++b and ++a) is crucial. The result may vary depending on the compiler and optimization settings.
    Based on the original code:
    cCopy code
    #include <stdio.h> int main() { int a = 10, b = 25; a = b++ + a++; b = ++b + ++a; printf("%d %d\n", a, b); return 0; }
    The expected output is 36 64.

    Rate this question:

  • 3. 

    Find Error/Output in following code: void fn() {   static int i = 10;   printf("%d ", ++i); } int main() {   fn();   fn(); }

    • A.

      10 10

    • B.

      11 11

    • C.

      11 12

    • D.

      12 12

    Correct Answer
    C. 11 12
    Explanation
    The code defines a function "fn" which has a static variable "i" initialized to 10. Inside the function, the value of "i" is incremented by 1 and then printed. The main function calls the "fn" function twice.

    When the "fn" function is called for the first time, the value of "i" is incremented to 11 and printed.

    When the "fn" function is called for the second time, the value of "i" is incremented again to 12 and printed.

    Therefore, the output will be "11 12".

    Rate this question:

  • 4. 

    Find Error/Output in following code: int main() {   int m = -10, n = 20;   n = (m < 0) ? 0 : 1;   printf("%d %d", m, n); }

    • A.

      -10 0

    • B.

      10 20

    • C.

      20 -10

    • D.

      0 1

    Correct Answer
    A. -10 0
    Explanation
    The code initializes two variables, m and n, to -10 and 20 respectively. It then assigns the value of 0 to n if m is less than 0, otherwise it assigns the value of 1 to n. Finally, it prints the values of m and n, which are -10 and 0 respectively.

    Rate this question:

  • 5. 

    Find Error/Output in following code: int main() {   int x = 0, y = 0;   if(x > 0)     if(y > 0)       printf("True");    else     printf("False");  }

    • A.

      No Output

    • B.

      True

    • C.

      False

    • D.

      Error - Dangling Problem

    Correct Answer
    A. No Output
    Explanation
    The code will not produce any output. This is because the if statement for y > 0 is nested inside the if statement for x > 0. Since x is initialized to 0, the condition x > 0 is false, and the nested if statement for y > 0 is never evaluated. Therefore, no output is printed.

    Rate this question:

  • 6. 

    What is output : #include <stdio.h> int main() { printf("crazyfor\\code\n"); return 0; }  

    • A.

      Crazyforcode

    • B.

      Crazyfor code

    • C.

      Crazyfor\code

    • D.

      Crazyfor

    Correct Answer
    C. Crazyfor\code
    Explanation
    The printf statement is used to print the string "crazyfor\code\n" to the standard output. The backslash (\) is an escape character in C, and when followed by another backslash (\\), it represents a single literal backslash in the output.

    Rate this question:

  • 7. 

    Output of following program? # include <stdio.h> void fun(int *ptr) {     *ptr = 30; }   int main() {   int y = 20;   fun(&y);   printf("%d", y);     return 0; }

    • A.

      20

    • B.

      30 

    • C.

      Compile Error 

    • D.

      Runtime Error

    Correct Answer
    B. 30 
    Explanation
    The program defines a function `fun` that takes a pointer to an integer as a parameter. Inside the function, the value at the memory address pointed to by `ptr` is changed to 30.

    In the `main` function, an integer variable `y` is declared and initialized to 20. The function `fun` is called with the address of `y` as an argument. This means that the function will modify the value at the memory address of `y`, changing it to 30.

    Finally, the value of `y` is printed, which is now 30. Therefore, the output of the program is 30.

    Rate this question:

  • 8. 

    char *ptr; char myString[]="abcdefg"; ptr=myString ptr+=5; The pointer ptr points to which string?

    • A.

      Fg

    • B.

      Efg

    • C.

      Defg

    • D.

      Cdefg

    Correct Answer
    A. Fg
    Explanation
    The pointer ptr points to the string "fg". This is because the pointer initially points to the start of the string "abcdefg" and then it is incremented by 5, causing it to point to the character 'f' in the string.

    Rate this question:

  • 9. 

    Given float *pf; int *pi; Which of the following is true?

    • A.

      Sizeof(pf) > sizeof(pi)

    • B.

      Sizeof(pi) < sizeof(pf)

    • C.

      Sizeof(pf) == sizeof(pi)

    • D.

      None

    Correct Answer
    C. Sizeof(pf) == sizeof(pi)
    Explanation
    The correct answer is "sizeof(pf) == sizeof(pi)". This is because the sizeof operator returns the size in bytes of its operand. In this case, both pf and pi are pointers, and the size of a pointer is typically the same regardless of the type it points to. Therefore, the sizes of pf and pi will be the same.

    Rate this question:

  • 10. 

    Which of the following is not a valid C variable name?

    • A.

       int number;

    • B.

      Float rate;

    • C.

      Int variable_count

    • D.

      Int $main;

    Correct Answer
    D. Int $main;
    Explanation
    The variable name "int $main;" is not a valid C variable name because variable names in C cannot start with a special character such as "$". Variable names in C can only start with a letter or an underscore.

    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 20, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 29, 2019
    Quiz Created by
    Shrenya Mathur
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.