C Language Test 5

    Question 1: Data Type Modifiers

    The long data type modifier is used to:

    Question 2: Logical NOT Operator

    What is the value of the expression !0?

    Question 3: Nested If Statements

    What is the output of the following C code?

    #include int main() { int a = 5, b = 10; if (a < b) { if (a == 5) { printf("Correct"); } } else { printf("Incorrect"); } return 0; }

    Question 4: Infinite Loop

    Which of these will create an infinite loop?

    Question 5: Standard Library Header

    Which header file must be included to use sqrt() function?

    Question 6: Strings as Arrays

    Which of the following is the correct declaration of a string in C?

    Question 7: Dangling Pointer

    When does a dangling pointer occur in C?

    Question 8: Structure vs Array

    Which statement is true?

    Question 9: fread() Function

    What does this code do?

    #include <stdio.h> struct Data { int x; float y; }; int main() { struct Data d; FILE *fp = fopen("bin.dat", "rb"); fread(&d, sizeof(d), 1, fp); fclose(fp); return 0; }

    Question 10: String vs Character

    Which of the following is a string constant in C?

    Question 11: Guess the Output - Constant Declaration

    What is the output of the following code?

    #include <stdio.h> #define PI 3.14 int main() { printf("%f", PI * 2); return 0; }

    Question 12: C Ternary Operator

    What is the output of the following C code?

    #include <stdio.h> int main() { int age = 20; printf("%s", (age >= 18) ? "Adult" : "Minor"); return 0; }

    Question 13: Logical Operators in If

    What is the output of the following C code?

    #include int main() { int temp = 25; if (temp > 20 && temp < 30) { printf("Pleasant"); } else { printf("Extreme"); } return 0; }

    Question 14: Loop Control

    Which loop is best suited when the number of iterations is known in advance?

    Question 15: Void Functions

    What is true about a void function in C?

    Question 16: Sizeof Operator

    If int arr[10]; and sizeof(int) = 4, what will sizeof(arr) return?

    Question 17: Function Pointers

    Which is the correct syntax to declare a pointer to a function that takes int as argument and returns int?

    Question 18: Union Size

    What will sizeof return?

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

    Question 19: fclose() Function

    Why should fclose() always be used after file operations?

    Question 20: strchr() Function

    Which standard library function is used to find the first occurrence of a character in a string?