C Programming Practice - Test 6

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 Nchaudhuri31
N
Nchaudhuri31
Community Contributor
Quizzes Created: 20 | Total Attempts: 8,596
Questions: 10 | Attempts: 81

SettingsSettingsSettings
C Programming Practice - Test 6 - Quiz

. Dear Learner,
This Assessment consists of questions to test your understanding on - C Programming
You may attempt the same and clarify doubts in WP Group. / With your Faculty Member
Regards,
Team SHIVAM


Questions and Answers
  • 1. 

    Pick up the right alternative void main() { int const * p=5; printf("%d",++(*p)); }

    • A.

      No Output

    • B.

      Garbage Value

    • C.

      Compiler Error

    • D.

      Linker Error

    Correct Answer
    C. Compiler Error
    Explanation
    The given code will result in a compiler error because it is trying to modify a constant value. The variable 'p' is declared as a pointer to a constant integer, and then it is assigned the value 5. However, the code then tries to increment the value pointed to by 'p' using the '++' operator, which is not allowed for constant variables. Therefore, the code will not compile successfully.

    Rate this question:

  • 2. 

    Pick up the right alternative main() { extern int i; i=20; printf("%d",i); }

    • A.

      No Output

    • B.

      Garbage Value

    • C.

      Compiler Error

    • D.

      Linker Error

    Correct Answer
    D. Linker Error
    Explanation
    The given code snippet declares an external variable 'i' without defining it. When the variable 'i' is assigned the value 20, the linker is unable to find the definition of 'i' in any other file. Therefore, a linker error occurs.

    Rate this question:

  • 3. 

    Pick up the right alternative main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }

    • A.

      Compiler Error

    • B.

      Garbage Value

    • C.

      No Output

    • D.

      Linker Error

    Correct Answer
    A. Compiler Error
    Explanation
    The code will give a compiler error because the function display is called before it is declared. In C, functions need to be declared before they are used. To fix this error, the display function should be declared before the main function.

    Rate this question:

  • 4. 

    Pick up the right alternative main() { clrscr(); } clrscr();

    • A.

      Compiler Error

    • B.

      Garbage Value

    • C.

      No Output

    • D.

      Linker Error

    Correct Answer
    C. No Output
    Explanation
    The given code is a simple C program that includes a main function. The function clrscr() is called twice in the code, once before the main function and once after it. However, the clrscr() function does not exist in the standard C library. Therefore, the compiler will throw an error stating that the clrscr() function is undefined. As a result, the code will not compile and there will be no output.

    Rate this question:

  • 5. 

    Pick up the right alternative main() { int x=5,y; x=y; printf(“%d %d”, x, y); }

    • A.

      Compiler Error

    • B.

      Garbage Value

    • C.

      No Output

    • D.

      Linker Error

    Correct Answer
    B. Garbage Value
    Explanation
    In this code, the variable y is not initialized before it is assigned to x. Therefore, the value of y is undefined or garbage. When the values of x and y are printed, the value of x will be garbage as it is assigned the garbage value of y. The value of y will also be garbage since it was never assigned a value. Hence, the correct answer is Garbage Value.

    Rate this question:

  • 6. 

    Pick up the right alternative #include void main() { int x=5,*y; x=y; printf("%d %d",*x,*y); }

    • A.

      Compiler Error

    • B.

      Garbage Value

    • C.

      No Output

    • D.

      Linker Error

    Correct Answer
    A. Compiler Error
    Explanation
    The code is attempting to assign the value of the pointer variable 'y' to the integer variable 'x', which is not allowed as they are of different types. This results in a compiler error.

    Rate this question:

  • 7. 

    Pick up the right alternative void main() { float *x=0.5; int *y; y=x; printf("%d",*y); }

    • A.

      Compiler Error

    • B.

      Garbage Value

    • C.

      No Output

    • D.

      Linker Error

    Correct Answer
    A. Compiler Error
    Explanation
    The given code will result in a compiler error. This is because the variable "x" is declared as a float pointer but it is assigned a float value directly, without using the address-of operator. This will cause a type mismatch error.

    Rate this question:

  • 8. 

    Pick up the right alternative #include void main() { char *str="abcdef"; int n=str; printf("%d",n); }

    • A.

      Compiler error

    • B.

      Garbage value

    • C.

      Warning

    • D.

      Linker error

    Correct Answer
    C. Warning
    Explanation
    The code is attempting to assign a character string to an integer variable, which can cause a warning. This is because the address of the string is being assigned to the integer variable, which may lead to unexpected behavior or errors.

    Rate this question:

  • 9. 

    Pick up the right alternative void main() { int n; n=scanf("%d",&n)+printf("%d",n); print("%d",n); }

    • A.

      Compiler Error

    • B.

      Garbage value

    • C.

      Warning

    • D.

      Linker error

    Correct Answer
    D. Linker error
    Explanation
    In the given code, there is a mistake in the print statement. The correct function to print in C is "printf", not "print". This mistake will result in a linker error because the compiler will not be able to find the function "print" and link it with the code.

    Rate this question:

  • 10. 

    Pick up the right alternative void main() { int *x=10,*y='a'; char *p=97; if(*p==*y) printf("%d",*x); }

    • A.

      Compiler Error

    • B.

      Garbage value

    • C.

      No Output

    • D.

      Linker error

    Correct Answer
    C. No Output
    Explanation
    The code will not produce any output because it contains several errors. The variables x, y, and p are declared as pointers but are assigned integer and character values directly instead of memory addresses. This will result in a compiler error. Additionally, the comparison *p==*y is comparing the values pointed to by p and y, which are both character values. Since the values 'a' and 97 are not equal, the condition will evaluate to false and the printf statement will not be executed. Therefore, there will be no output.

    Rate this question:

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.