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