Can You Pass This C Language Coding Test?

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 Mohit Mishra
M
Mohit Mishra
Community Contributor
Quizzes Created: 1 | Total Attempts: 11,047
Questions: 10 | Attempts: 11,047

SettingsSettingsSettings
Can You Pass This C Language Coding Test? - Quiz

C is a programming language which was developed by Dennis Ritchie. C language incorporates low-level access to memory, clean style and simple set of keywords which makes 'C' language a perfect system programming like Operating system. This quiz has been designed to test your programming skills and basic knowledge about C language. There is a set of 10 questions. Read the questions carefully and answer. So, let's try out the quiz. All the best!


Questions and Answers
  • 1. 

    Void main() { int const * p=5; printf("%d",++(*p)); }

    • A.

      COMPILER ERROR

    • B.

      6

    • C.

      ADDRESS VALUE

    • D.

      5

    • E.

      NONE

    Correct Answer
    A. COMPILER ERROR
    Explanation
    The given code will result in a compiler error because it is attempting to modify the value of a constant variable. The variable 'p' is declared as a pointer to a constant integer using the 'const' keyword, and then it is assigned the value 5. However, when the code tries to increment the value pointed to by 'p' using the '++' operator, it is not allowed because 'p' is a pointer to a constant value. This violates the const-correctness rule and leads to a compiler error.

    Rate this question:

  • 2. 

    Main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }

    • A.

      Mmm aaaa nnnnn

    • B.

      Mmmmm aaa nnnn

    • C.

      Mmmm aaaa nnnn

    • D.

      Mmm aaa nnn

    • E.

      NONE

    Correct Answer
    C. Mmmm aaaa nnnn
    Explanation
    The given code is a C program that prints a pattern based on the characters in the string "man". The for loop iterates through each character in the string. Inside the loop, the printf statement is used to print the characters in different ways.

    In the first iteration of the loop, the characters 'm', 'a', and 'n' are printed using different methods: s[i], *(s+i), *(i+s), and i[s].

    The output of the program will be "mmmm", "aaaa", and "nnnn" printed on separate lines. Therefore, the correct answer is "mmmm aaaa nnnn".

    Rate this question:

  • 3. 

    6. main() { extern int i; i=20; printf("%d",i); }

    • A.

      LINKER ERROR

    • B.

      COMPILER ERROR

    • C.

      20

    • D.

      ADDRESS

    • E.

      NONE

    Correct Answer
    A. LINKER ERROR
    Explanation
    The code is trying to access a variable "i" that is declared as extern, which means it is defined in another file. However, there is no definition or declaration of "i" in the current file. This leads to a linker error because the linker is unable to find the definition of "i" and link it with the code. Therefore, the correct answer is LINKER ERROR.

    Rate this question:

  • 4. 

    Predict the output of the following C snippets int main() {     int main = 56;     printf("%d", main);     return 0; }

    • A.

      Compiler Error

    • B.

      Depends on the compiler

    • C.

      56

    • D.

      None of above

    Correct Answer
    C. 56
    Explanation
    main is not a keyword in C.

    Rate this question:

  • 5. 

    What is the output of this C code? #include int main() {    float a = 3.14, *fptr;    fptr = &a;      printf("Size of Float Pointer : %d", sizeof(fptr));    return (0); }  

    • A.

      Size of Float Pointer : 2

    • B.

      Size of Float Pointer : 4

    • C.

      Size of Float Pointer : 6

    • D.

      Size of Float Pointer : 8

    Correct Answer
    D. Size of Float Pointer : 8
    Explanation
    The correct answer is "Size of Float Pointer : 8". In this code, a float variable "a" is declared and assigned a value of 3.14. Then, a float pointer "fptr" is declared and assigned the address of "a". The sizeof() function is used to determine the size of the float pointer "fptr", which is 8 bytes on most systems.

    Rate this question:

  • 6. 

    What is the output of the below c code? #include<stdio.h> int main() {     char ch;     if(ch = printf(""))         printf("It matters\n");     else         printf("It doesn't matters\n");     return 0; }

    • A.

       It matters

    • B.

      It doesn’t matters

    • C.

      Run time error

    • D.

       Nothing

    Correct Answer
    B. It doesn’t matters
    Explanation
    printf returns the number of characters successfully written on output.Hence ch=0 and else statement executes.

    Rate this question:

  • 7. 

    Which one do you like? int main() {     fork();     fork();     printf("Hello world\n"); }  

    • A.

      1

    • B.

      2

    • C.

      4

    • D.

      8

    Correct Answer
    C. 4
    Explanation
    fork is an operation wherein the process makes another copy of itself.

    Rate this question:

  • 8. 

    What is the output of this C code? void main() {     int i, j;     for(i=0,j=0;i<10,j<20;i++,j++){         printf("i=%d \t j=%d\n", i, j);     } }

    • A.

      Print i and j till 19

    • B.

      Print i till 9 and j till 19

    • C.

      Print i and j till 9

    • D.

       Runtime error

    Correct Answer
    A. Print i and j till 19
    Explanation
    The code uses a comma operator in the condition of the for loop. The comma operator evaluates both expressions and returns the value of the second expression. In this case, the loop will continue as long as both i is less than 10 and j is less than 20. Since both variables are incremented in each iteration, they will eventually reach 19. Therefore, the code will print the values of i and j until they both reach 19.

    Rate this question:

  • 9. 

    What is the output of this C code? #include<stdio.h> int main() {     int x=1, y=0,z=5;     int a=x&&y||++z;     printf("%d",z++); }

    • A.

      1

    • B.

      5

    • C.

      6

    • D.

      7

    Correct Answer
    C. 6
    Explanation
    and operator doesnt operate if second argument is zero. & operator has more precedence than ||

    Rate this question:

  • 10. 

    What is the output of this C code? #include<stdio.h> int main() {     int y = 2;     int z = y +(y = 10);     printf("%d\n", z); }

    • A.

      2

    • B.

      4

    • C.

      20

    • D.

      Compile error 

    Correct Answer
    C. 20
    Explanation
    The output of this C code is 20. In the line "int z = y +(y = 10)", the value of y is first assigned as 10 and then added to itself, resulting in z being assigned a value of 20. The printf statement then prints the value of z, which is 20.

    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
  • Apr 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 06, 2008
    Quiz Created by
    Mohit Mishra
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.