C Language Test 4

    Question 1Variable Naming Rules

    Which of the following is a valid variable name in C?

    Question 2Assignment Operators

    The expression x += 5; is equivalent to which of the following?

    Question 3If-Else Statement

    What is the output of the following C code?

    #include int main() { int num = 7; if (num % 2 == 0) { printf("Even"); } else { printf("Odd"); } return 0; }

    Question 4While Loop Execution

    What will be the output?

    #include <stdio.h> int main() { int i = 0; while (i < 3) { printf("Hi "); i++; } return 0; }

    Question 5Recursive Function

    Which of the following functions is an example of recursion?

    Question 62D Array Size

    How many elements does an array int arr[3][4]; contain?

    Question 7Pointer Arithmetic

    If p is an integer pointer pointing to address 1000, what will p+1 point to (assuming 4-byte int)?

    Question 8Union Behavior

    What will be printed?

    #include <stdio.h> union Data { int i; char c; }; int main() { union Data d; d.i = 65; printf("%c", d.c); return 0; }

    Question 9fputc() Function

    What will this program do?

    #include <stdio.h> int main() { FILE *fp = fopen("test.txt", "w"); fputc('Z', fp); fclose(fp); return 0; }

    Question 10gets() Function

    Why is gets() considered unsafe in C?

    Question 11Guess the Output - sizeof Operator

    Assuming a 32-bit system, what is the output of this code?

    #include <stdio.h> int main() { printf("%lu", sizeof(char)); return 0; }

    Question 12Operator Precedence

    What is the output of the following C code?

    #include <stdio.h> int main() { printf("%d", 10 + 5 * 2); return 0; }

    Question 13Else-If Ladder

    What is the output of the following C code?

    #include int main() { int score = 85; if (score >= 90) { printf("A"); } else if (score >= 80) { printf("B"); } else { printf("C"); } return 0; }

    Question 14Nested Loop

    If an outer loop runs 5 times and an inner loop runs 4 times, how many total iterations occur?

    Question 15Recursion Example

    What is the output of the following code?

    #include <stdio.h> int fact(int n) { if (n == 0) return 1; return n * fact(n - 1); } int main() { printf("%d", fact(3)); return 0; }

    Question 162D Array Access

    What will be printed?

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

    Question 17Double Pointer

    What will be the output?

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

    Question 18Nested Structures

    Which of the following is valid for nested structures?

    Question 19EOF Constant

    What does EOF stand for in C file handling?

    Question 20strcpy() Function

    What will be printed?

    #include <stdio.h> #include <string.h> int main() { char str1[10]; strcpy(str1, "Code"); printf("%s", str1); return 0; }