C Language Test 3

    Question 1: Floating-Point Data Type

    How do you declare a variable named pi to store the value 3.14159 with high precision?

    Question 2: Pre-increment Operator

    What is the value of y after the following C code executes?

    #include <stdio.h> int main() { int x = 5; int y = ++x; return 0; }

    Question 3: The default case

    The default case in a switch statement serves what purpose?

    Question 4: Continue Statement

    What does the continue statement do inside a loop?

    Question 5: Function with Parameters

    What will be the output?

    #include <stdio.h> int add(int a, int b) { return a + b; } int main() { printf("%d", add(3, 4)); return 0; }

    Question 6: Array and Loop

    What will be printed?

    #include <stdio.h> int main() { int arr[4] = {2, 4, 6, 8}; for (int i = 0; i < 4; i++) { printf("%d ", arr[i]); } return 0; }

    Question 7: NULL Pointer

    What does a NULL pointer represent in C?

    Question 8: Difference between Structure and Union

    What is the key difference between structure and union in C?

    Question 9: File Modes

    What does mode "a" do in fopen()?

    Question 10: strcat() Function

    What will be printed?

    #include <stdio.h> #include <string.h> int main() { char str1[20] = "Hi "; char str2[] = "C"; strcat(str1, str2); printf("%s", str1); return 0; }

    Question 11: Guess the Output - Type Promotion

    What is the output of the following code?

    #include <stdio.h> int main() { int a = 10; float b = 3.0; printf("%.2f", a / b); return 0; }

    Question 12: Post-decrement Operator

    What will be the final value of x after the following C code executes?

    #include <stdio.h> int main() { int x = 8; int y = x--; return 0; }

    Question 13: Simple If Statement

    What is the output of the following C code?

    #include int main() { int x = 10; if (x == 10) { printf("True"); } else { printf("False"); } return 0; }

    Question 14: For Loop Output

    What will be printed?

    #include <stdio.h> int main() { for (int i = 1; i <= 3; i++) { printf("%d ", i); } return 0; }

    Question 15: Function Call by Value

    What will be printed?

    #include <stdio.h> void change(int x) { x = 100; } int main() { int a = 5; change(a); printf("%d", a); return 0; }

    Question 16: Array Out of Bounds

    What happens if we try to access arr[10] when arr has size 5?

    Question 17: Pointer and Array

    What will be the output?

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

    Question 18: Size of Structure

    What will sizeof return?

    #include <stdio.h> struct Test { int a; char b; }; int main() { printf("%zu", sizeof(struct Test)); return 0; }

    Question 19: fgetc() Function

    What will be the output if input.txt contains AB?

    #include <stdio.h> int main() { FILE *fp = fopen("input.txt", "r"); char ch = fgetc(fp); printf("%c", ch); fclose(fp); return 0; }

    Question 20: strcmp() Function

    What will strcmp("apple", "apple") return?