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