C Language Test 2

    Question 1: Character Data Type

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

    Question 2: Modulus Operator

    What is the result of the expression 20 % 6?

    Question 3: Purpose of switch statement

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

    Question 4: Do-While Loop

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

    Question 5: Function Declaration

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

    Question 6: Array Initialization

    Which of the following correctly initializes an array in C?

    Question 7: Pointer 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 8: Structure 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 9: fopen() 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 10: strlen() Function

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

    Question 11: Guess 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 12: Logical 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 13: The break keyword

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

    Question 14: Break Statement

    What does the break statement do inside a loop?

    Question 15: Return Type

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

    Question 16: Accessing 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 17: Pointer 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 18: Pointer 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 19: fprintf() 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 20: puts() Function

    What will this program print?

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