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