C Programming Quiz by azka.xdlabin QuizMarch 4, 2025 C Programming Quiz 1 / 100 Which of the following is NOT a type of loop in C? for loop while loop do-while loop foreach loop 2 / 100 Can the conditional expression in an if statement be non-integer values? Only boolean values are allowed Yes, it can be any non-zero value No, only integers are allowed Only float values are allowed 3 / 100 Can an array size be changed after declaration in C? Yes, using resize function No, array size is fixed Yes, using the realloc function Yes, by assigning a new array 4 / 100 Which statement is true about an enum? Enum variables can store any integer value, not just the defined constants Enum constants can have floating-point values Enum constants can be repeated within the same enum Enum constants must be unique 5 / 100 What is the correct way to declare and initialize a structure variable? struct MyStruct s = {10, 3.5}; struct s = {10, 3.5}; MyStruct s = {10, 3.5}; s = {10, 3.5}; 6 / 100 What happens if the condition in a loop is always true? The compiler will throw an error The loop will exit after 10 iterations The loop will run indefinitely (infinite loop) The program will crash 7 / 100 Which of the following statements is true about structures? A structure can contain functions A structure cannot have another structure as a member A structure is the same as a class in C++ A structure can have an array as a member 8 / 100 What is the ASCII value of '0'? 49 48 -48 0 9 / 100 What is the correct way to call a function? functionName(); execute functionName(); call functionName; functionName = call; 10 / 100 What is the output of the following program? 1 2 4 5 1 2 1 2 3 1 2 3 4 5 11 / 100 What is the correct syntax to declare a pointer to an integer? int ptr*; ptr int*; int *ptr; *int ptr; 12 / 100 Which of the following is a logical operator in C? || All of the above && ! 13 / 100 How do you declare an enum variable in C? enum c = Color; enum Color c; c = enum Color; Color c; 14 / 100 What happens if break is used outside a loop or switch? It causes a compilation error It is ignored by the compiler It causes an infinite loop It works normally 15 / 100 Can a structure contain a pointer to itself? Only if the pointer is initialized Only in C++ No Yes 16 / 100 How do you declare a union variable in C? union Example obj; data union Example obj; struct Example obj; Example obj; 17 / 100 What is an enumeration (enum) in C? A data type that stores multiple values of different types A pointer to an integer array A user-defined data type consisting of named integer constants A type of structure that holds functions 18 / 100 What will happen if malloc() fails to allocate memory? Program crashes Returns 0 Returns NULL Undefined behavior 19 / 100 Which of the following is a conditional statement in C? while do-while for if 20 / 100 Which of the following is NOT a jump statement in C? continue break switch return 21 / 100 What does continue do in a while loop? Jumps to another function Causes an infinite loop Exits the loop Skips the remaining statements of the current iteration and continues with the next iteration 22 / 100 What is a function prototype in C? A function with no parameters A function declaration before its actual definition A function definition A function that doesn't return any value 23 / 100 What is the index of the first element in an array? 1 0 -1 Depends on the array size 24 / 100 How do you find the number of elements in an array in C? length(arr) size(arr) count(arr) sizeof(arr) / sizeof(arr[0]) 25 / 100 What is the main difference between break and continue? break can only be used in switch, continue can only be used in loops break and continue are the same continue stops loop execution, while break skips an iteration break stops loop execution, while continue skips an iteration 26 / 100 Which data type is used to store a single character in C? text char character string 27 / 100 What is a structure in C? A collection of variables of different data types under one name A keyword for memory allocation A collection of variables of the same data type A function that holds multiple variables 28 / 100 What is the purpose of the else if statement? It allows checking multiple conditions It terminates the program if no condition is true It runs only if the else statement runs It runs when the if condition is false 29 / 100 What will be the output of the following code? Compilation error 15 10 5 30 / 100 What is a Union in C ? A data structure that allows only integer values A user-defined data type where all members share the same memory location A collection of unrelated functions A special type of array 31 / 100 What will be the default value of GREEN in the following code?enum Color { RED, GREEN, BLUE }; 1 It depends on user input 0 2 32 / 100 What does the break statement do? Exits a loop or switch statement Jumps to a labeled statement Stops execution of a program Skips the current iteration of a loop 33 / 100 Which loop is used when the number of iterations is known? do-while for while switch 34 / 100 What is the output of the following code? 5 15 20 10 35 / 100 What is the keyword used to define a structure in C? typedef struct class structure 36 / 100 How do you define a union in C? union Data { int a; float b; }; data union { int a; float b; }; structure Data { int a; float b; }; Data union { int a; float b; }; 37 / 100 What is the purpose of the break statement? To jump to a labeled statement To skip the current iteration of a loop To exit a loop or switch statement To return a value from a function 38 / 100 What will be the output of this program? 3 4 5 1 2 4 5 Compilation error 1 2 3 4 5 39 / 100 How do you dynamically allocate memory in C? malloc(10 * sizeof(int)) memory(10) malloc(10) alloc(10) 40 / 100 What is the output of the following code? 15 Compilation error 5 10 41 / 100 Which operator is used for bitwise XOR? | ~ & ^ 42 / 100 How do you define a structure in C? struct MyStruct ( int a; float b; ); struct MyStruct { int a; float b; }; struct { int a; float b; } structure MyStruct { int a; float b; } 43 / 100 Which of the following correctly initializes an array? int arr[] = {1, 2, 3}; int arr[3] = {1, 2, 3}; int arr[3] = {1}; All of the above 44 / 100 What is the size of an enum in C? 8 bytes Same as a char (1 byte) Same as an int (usually 4 bytes) Depends on the number of members 45 / 100 What will be the output of the following code? 2 Compilation error 2.500000 2.000000 46 / 100 What is the difference between void and int functions? void functions do not return a value, while int functions return an integer void functions cannot have parameters int functions cannot use printf() int functions run faster than void functions 47 / 100 How are multi-dimensional arrays stored in memory? Row-major order (row-wise) Random order Not stored in memory Column-major order (column-wise) 48 / 100 How do you pass an argument by reference in C? Using a pointer (*) Using an ampersand (&) Using a return statement Using an array 49 / 100 In which of the following can break be used Both loops and switch switch only Loops only Functions only 50 / 100 What is a structure in C? A function that initializes variables A type of pointer A user-defined data type that groups different data types together A type of loop 51 / 100 Which of the following is the correct syntax for an if statement in C? if x > 5 then printf("Hello"); if (x > 5) printf("Hello"); if x > 5 { printf("Hello"); } if (x > 5) { printf("Hello"); } 52 / 100 Which of the following is a correct way to free allocated memory? clear(ptr); free(ptr); remove(ptr); delete ptr; 53 / 100 How do you access structure members in C? Using & operator Using * operator Using . operator Using -> operator 54 / 100 What will happen if you try to dereference a NULL pointer? Compilation error It will print NULL Program will crash It will print 0 55 / 100 What happens if recursion doesn't have a base case? The compiler automatically stops execution The program crashes due to stack overflow The function executes normally The recursion stops after 100 calls 56 / 100 What is a function prototype in C? A function that runs automatically A declaration of a function before its definition A function without a return value A built-in function in C 57 / 100 What is the difference between while and do-while loops? do-while loop executes at least once, while may not execute at all while loop checks the condition first, do-while checks it last No difference Both a & b 58 / 100 What is the correct syntax for a for loop? for(condition; initialization; update) { body } for(initialization; condition; update) { body } for(initialization, update, condition) { body } for(update; initialization; condition) { body } 59 / 100 Which of the following is NOT a valid format specifier in C? %p% %d %Lf %lf 60 / 100 What is the format specifier for printing an integer in C? %c %s %f %d 61 / 100 How do you define a structure in C? define struct { int x; float y; }; struct { int x; float y; }; struct MyStruct { int x; float y; }; structure MyStruct { int x; float y; }; 62 / 100 What is a pointer in C? A variable that stores the address of another variable A data type A function that returns memory size A keyword used to store addresses 63 / 100 Which operator is used to get the address of a variable? @ # * & 64 / 100 Which statement is not a jump statement? break continue switch goto 65 / 100 What is the purpose of typedef with unions? To allocate memory dynamically To improve execution speed To prevent modification of union members To create an alias for the union type 66 / 100 What is the output of this program? Hello World Compilatoin error World Hello 67 / 100 Which of the following is required to prevent infinite recursion? A break statement A loop inside the function A base condition A goto statement 68 / 100 What is the purpose of the return 0; statement in the main() function? It indicates successful program termination It is used to return a value to printf It is required in every C program It is used to take input from the user 69 / 100 What will be the output of the following program? 1 2 3 4 5 1 2 3 4 1 2 3 1 2 70 / 100 How do you define an enumeration in C? enum { RED, GREEN, BLUE } Color; define enum Color { RED, GREEN, BLUE }; enumeration Color { RED, GREEN, BLUE }; enum Color { RED, GREEN, BLUE }; 71 / 100 Which of the following statements about recursion is false? Recursion always uses more memory than iteration Every recursion must have a base case Recursion is faster than iteration in all cases Recursion always uses more memory than iteration 72 / 100 What is the correct syntax to declare a variable in C? int x; variable x; x int; int = x; 73 / 100 What happens if two enumeration constants have the same value? Compilation error Runtime error Causes undefined behavior Allowed without any error 74 / 100 How do you terminate a loop immediately in C? exit(0) return break continue 75 / 100 What is the main difference between a struct and a union? A struct stores all its members separately, while a union shares memory among all members A struct uses less memory than a union A union allows multiple values to be stored simultaneously There is no difference between them 76 / 100 What is the output of this program? Compilation Error 3 2 1 1 2 3 1 77 / 100 What is the main advantage of recursion? It prevents stack overflow It always runs faster than loops It makes code shorter and easier to understand It reduces memory usage 78 / 100 How do you access a structure member? struct.member() struct->member struct.member struct:member 79 / 100 What is Recursion in C ? A function that runs infinitely A function that calls itself A function with multiple return values A function with no parameters 80 / 100 What is an array in C? A collection of variables of different data types A collection of variables of the same data type stored in contiguous memory A function that stores multiple values A pointer that stores memory addresses 81 / 100 What is the size of an int variable in C (typically on a 32-bit system)? 4 bytes 2 bytes 1 byte 8 bytes 82 / 100 Which of the following is a correct function prototype? sum(int a, int b); sum(a, b); int sum(int a, int b); int sum(a, b); 83 / 100 Where can continue be used? Inside functions only Inside switch statements Inside loops only Inside if-else blocks 84 / 100 What is the purpose of typedef in structures? To allocate memory dynamically To create an alias for an existing function To prevent modification of structure members To simplify the declaration of structure variables 85 / 100 How do you access structure members using a pointer? ptr.member ptr->member ptr(member) ptr:member 86 / 100 What is a function in C? A block of code that performs a specific task A keyword used for iteration A loop structure A variable that stores multiple values 87 / 100 What is the purpose of a function prototype? To inform the compiler about the function before its use To define the function To prevent function calls To improve execution speed 88 / 100 Which operator is used to access union members? . * & -> 89 / 100 What will be the output of this code? 1 2 3 Compilation error 1 2 3 90 / 100 What is the best practice regarding goto in C? Use it frequently for better readability Use it only in switch statements Avoid using it as much as possible It is required in all C programs 91 / 100 What is the correct syntax to declare a function in C? declare function functionName(); void = functionName(); void functionName(); functionName() void; 92 / 100 Which statement is used to exit a switch case? stop break return exit 93 / 100 Which of the following is the assignment operator in C? = += != == 94 / 100 Which of the following is used to read input from the user in C? scanf print printf getchar 95 / 100 How do you declare a pointer to a structure? Student ptr; struct Student* ptr; Student* ptr; ptr struct Student; 96 / 100 Which statement is true about return? It can be used in loops to skip an iteration It can only be used in main() It is used to return a value from a function It stops execution but does not return control to the calling function 97 / 100 What is a dangling pointer? A pointer that is uninitialized A pointer that points to NULL A pointer that stores an address in hexadecimal A pointer that points to a deallocated memory location 98 / 100 How do you declare an integer array of size 5 in C? array int arr[5]; int arr(5); int arr[5]; int[5] arr; 99 / 100 What happens if you access an array index that is out of bounds? It will cause a compilation error It will always print 0 The program will terminate immediately It may cause unpredictable behavior (segmentation fault) 100 / 100 What will happen if a function is used without a prototype in C? The function will execute twice The program may give a compilation warning or error The program will run normally The function will be ignored by the compiler Your score isThe average score is 66% 0% Restart quiz