C Language Test 2

    Question 1Character Data Type

    Which of the following data types is used to store a single character and occupies 1 byte of memory?

    Question 2Modulus Operator

    What is the result of the expression 20 % 6?

    Question 3Purpose of switch statement

    The switch statement is best suited for scenarios where you need to:

    Question 4Do-While Loop

    What is the key difference between a while and a do-while loop?

    Question 5Function Declaration

    Where is a function prototype (declaration) usually placed in a C program?

    Question 6Array Initialization

    Which of the following correctly initializes an array in C?

    Question 7Pointer Dereferencing

    What will be the output of this program?

    #include <stdio.h> int main() { int x = 10; int *p = &x; printf("%d", *p); return 0; }

    Question 8Structure Access

    What will be the output?

    #include <stdio.h> struct Point { int x, y; }; int main() { struct Point p = {10, 20}; printf("%d %d", p.x, p.y); return 0; }

    Question 9fopen() Error Handling

    What will this program print if data.txt does not exist?

    #include <stdio.h> int main() { FILE *fp; fp = fopen("data.txt", "r"); if (fp == NULL) printf("File not found"); else printf("File opened"); return 0; }

    Question 10strlen() Function

    If char str[] = "C Language";, what will strlen(str) return?

    Question 11Guess the Output - Type Mismatch

    What will be the output of the following C code snippet?

    #include <stdio.h> int main() { int num = 'C'; printf("%d", num); return 0; }

    Question 12Logical AND Operator

    What is the output of the following C code?

    #include <stdio.h> int main() { int a = 10; int b = 5; printf("%d", (a > 5) && (b < 10)); return 0; }

    Question 13The break keyword

    What is the main purpose of the break keyword inside a switch statement?

    Question 14Break Statement

    What does the break statement do inside a loop?

    Question 15Return Type

    What does a function return if its return type is not specified in C (default)?

    Question 16Accessing Array Elements

    What will the following code print?

    #include <stdio.h> int main() { int arr[3] = {10, 20, 30}; printf("%d", arr[1]); return 0; }

    Question 17Pointer Assignment

    What will be printed?

    #include <stdio.h> int main() { int a = 5, b = 20; int *p = &a; p = &b; printf("%d", *p); return 0; }

    Question 18Pointer to Structure

    What will be printed?

    #include <stdio.h> struct Student { int id; }; int main() { struct Student s = {101}; struct Student *p = &s; printf("%d", p->id); return 0; }

    Question 19fprintf() Function

    What will this program do?

    #include <stdio.h> int main() { FILE *fp = fopen("out.txt", "w"); fprintf(fp, "Hello C"); fclose(fp); return 0; }

    Question 20puts() Function

    What will this program print?

    #include <stdio.h> int main() { char str[] = "Hello"; puts(str); return 0; }