Quiz 1:
What does the acronym ‘ASCII’ stand for in C programming?
- HyperText Markup Language (HTML)
- American Standard Code for Information Interchange (ASCII)
- Advanced Structured Coding Interface (ASCI)
- Automated System for Code Integration (ASCI)
Correct Answer: 2. American Standard Code for Information Interchange (ASCII)
Explanation: ASCII is a character encoding standard that represents text in computers, communications equipment, and other devices.
Quiz 2:
In C, which keyword is used to define a constant?
- var
- define
- constant
- const
Correct Answer: 4. const
Explanation: The const keyword is used to define constants in C, making the value unmodifiable.
Quiz 3:
What is the purpose of the ‘break’ statement in a switch-case statement?
- Skip the current iteration
- Exit the loop
- Terminate the program
- Exit the switch block
Correct Answer: 4. Exit the switch block
Explanation: The ‘break’ statement is used to exit the switch block once a matching case is found.
Quiz 4:
Which operator is used for dynamic memory allocation in C?
- new
- malloc
- alloc
- allocate
Correct Answer: 2. malloc
Explanation: The malloc function is used to allocate memory dynamically in C.
Quiz 5:
What does the ‘sizeof’ operator return in C?
- Size of a variable
- Size of a function
- Size of a pointer
- Size of a constant
Correct Answer: 1. Size of a variable
Explanation: The ‘sizeof’ operator returns the size, in bytes, of the specified variable or data type.
Quiz 6:
Which header file should be included to use the ‘printf’ function in C?
- input.h
- output.h
- stdio.h
- stdlib.h
Correct Answer: 3. stdio.h
Explanation: The ‘printf’ function is part of the Standard Input/Output library in C, and the header file stdio.h should be included.
Quiz 7:
What is the role of the ‘void’ keyword in a function declaration?
- Specifies the return type
- Represents an empty function
- Declares a variable
- Indicates a pointer type
Correct Answer: 1. Specifies the return type
Explanation: The ‘void’ keyword is used to indicate that a function does not return any value.
Quiz 8:
Which of the following is the correct way to comment out multiple lines in C?
- # Comment #
- /* Comment */
- // Comment
- % Comment %
Correct Answer: 2. /* Comment */
Explanation: Multiple-line comments in C are enclosed between /* and */.
Quiz 9:
What is the purpose of the ‘typedef’ keyword in C?
- Declare a new type name
- Define a constant
- Specify the data type of a variable
- Allocate memory dynamically
Correct Answer: 1. Declare a new type name
Explanation: ‘typedef’ is used to create a new type name for an existing data type.
Quiz 10:
Which function is used to read a character from the standard input in C?
- getchar()
- readchar()
- scanchar()
- read()
Correct Answer: 1. getchar()
Explanation: getchar() is used to read a single character from the standard input (keyboard).
Quiz 11:
What is the purpose of the ‘strcmp’ function in C?
- Concatenate two strings
- Compare two strings
- Convert a string to uppercase
- Find the length of a string
Correct Answer: 2. Compare two strings
Explanation: The ‘strcmp’ function is used to compare two strings in C.
Quiz 12:
Which loop is known as an entry-controlled loop in C?
- for loop
- while loop
- do-while loop
- if loop
Correct Answer: 1. for loop
Explanation: The for loop is an entry-controlled loop in C.
Quiz 13:
In C, how are single-line comments denoted?
- // Comment
- /* Comment */
- # Comment #
- ! Comment !
Correct Answer: 1. // Comment
Explanation: Single-line comments in C are indicated by //.
Quiz 14:
Which escape sequence is used for a new line in C?
- \n
- \r
- \t
- \a
Correct Answer: 1. \n
Explanation: \n represents a new line character in C.
Quiz 15:
What is the purpose of the ‘do-while’ loop in C?
- Execute a block of code while a condition is true
- Execute a block of code at least once
- Loop through an array
- Iterate over a range of values
Correct Answer: 2. Execute a block of code at least once
Explanation: The ‘do-while’ loop ensures that the code block is executed at least once, even if the condition is false.
Quiz 16:
Which bitwise operator is used to set a particular bit to 1 in C?
- &
- |
- ^
- <<
Correct Answer: 2. |
Explanation: The bitwise OR (|) operator is used to set a particular bit to 1.
Quiz 17:
What is the purpose of the ‘return’ statement in a function in C?
- Exit the program
- Return a value from the function
- Declare a variable
- Print a message
Correct Answer: 2. Return a value from the function
Explanation: The ‘return’ statement is used to send a value back from a function.
Quiz 18:
Which data type is used to store a single character in C?
- int
- float
- char
- double
Correct Answer: 3. char
Explanation: The char data type is used to store a single character in C.
Quiz 19:
What is the purpose of the ‘continue’ statement in a loop in C?
- Skip the current iteration and move to the next
- Exit the loop
- Terminate the program
- Restart the loop from the beginning
Correct Answer: 1. Skip the current iteration and move to the next
Explanation: The ‘continue’ statement is used to skip the rest of the code inside a loop for the current iteration and move to the next one.
Quiz 20:
Which function is used to close a file in C?
- fclose()
- close()
- fileclose()
- shutfile()
Correct Answer: 1. fclose()
Explanation: The fclose() function is used to close a file in C after performing file operations.
Quiz 21:
Which of the following is the correct syntax for a structure declaration in C?
- structure MyStruct { /* members */ };
- struct MyStruct { /* members */ };
- type MyStruct { /* members */ };
- new struct MyStruct { /* members */ };
Correct Answer: 2. struct MyStruct { /* members */ };
Explanation: The correct syntax for a structure declaration in C is struct MyStruct { /* members */ };.
Quiz 22:
What is the purpose of the ‘sizeof’ operator in C?
- Return the size of a function
- Return the size of a pointer
- Return the size of a variable or data type
- Return the size of a constant
Correct Answer: 3. Return the size of a variable or data type
Explanation: The ‘sizeof’ operator in C is used to determine the size, in bytes, of a variable or data type.
Quiz 23:
Which operator is used for logical AND in C?
- &&
- ||
- !
- &
Correct Answer: 1. &&
Explanation: The && operator is used for logical AND in C.
Quiz 24:
In C, what is the purpose of the ‘void’ data type?
- Specify an empty variable
- Indicate the absence of a data type
- Define a constant value
- Represent a generic pointer type
Correct Answer: 2. Indicate the absence of a data type
Explanation: The ‘void’ data type in C is used to indicate the absence of a specific data type.
Quiz 25:
Which function is used to concatenate two strings in C?
- strcat()
- concat()
- merge()
- append()
Correct Answer: 1. strcat()
Explanation: The strcat() function in C is used to concatenate two strings.
Quiz 26:
What is the purpose of the ‘if’ statement in C?
- Iterate over a range of values
- Make decisions based on a condition
- Declare a variable
- Perform file operations
Correct Answer: 2. Make decisions based on a condition
Explanation: The ‘if’ statement in C is used to make decisions based on a specified condition.
Quiz 27:
Which operator is used for pointer dereferencing in C?
- *
- &
- ->
- %
Correct Answer: 1. *
Explanation: The * operator is used for pointer dereferencing in C.
Quiz 28:
What is the purpose of the ‘calloc’ function in C?
- Allocate memory dynamically
- Initialize memory to zero
- Free allocated memory
- Allocate memory for an array of elements
Correct Answer: 4. Allocate memory for an array of elements
Explanation: The ‘calloc’ function in C is used to allocate memory for an array of elements and initializes the memory to zero.
Quiz 29:
Which loop is known as an exit-controlled loop in C?
- do-while loop
- while loop
- for loop
- if loop
Correct Answer: 2. while loop
Explanation: The while loop is an exit-controlled loop in C.
Quiz 30:
What is the purpose of the ‘union’ keyword in C?
- Declare a new type name
- Represent a collection of variables
- Create an empty function
- Allocate memory dynamically
Correct Answer: 2. Represent a collection of variables
Explanation: The ‘union’ keyword in C is used to represent a collection of variables that share the same memory location.
Quiz 31:
Which header file should be included to use the ‘scanf’ function in C?
- input.h
- output.h
- stdio.h
- stdlib.h
Correct Answer: 3. stdio.h
Explanation: The ‘scanf’ function is part of the Standard Input/Output library in C, and the header file stdio.h should be included.
Quiz 32:
What is the purpose of the ‘for’ loop in C?
- Execute a block of code at least once
- Iterate over a range of values
- Make decisions based on a condition
- Skip the current iteration and move to the next
Correct Answer: 2. Iterate over a range of values
Explanation: The ‘for’ loop in C is used to iterate over a range of values with a specified control structure.
Quiz 33:
Which operator is used for the modulo operation in C?
- %
- &
- |
- ^
Correct Answer: 1. %
Explanation: The % operator is used for the modulo operation in C, which returns the remainder of a division.
Quiz 34:
What does the ‘sizeof’ operator return when used with a pointer in C?
- Size of the pointer variable
- Size of the data type to which the pointer points
- Total size of the memory allocated for the pointer
- Size of the memory address held by the pointer
Correct Answer: 1. Size of the pointer variable
Explanation: When used with a pointer, the ‘sizeof’ operator in C returns the size of the pointer variable.
Quiz 35:
Which function is used to open a file in C for writing?
- fopen(“filename”, “r”)
- fopen(“filename”, “w”)
- fopen(“filename”, “a”)
- fopen(“filename”, “rb”)
Correct Answer: 2. fopen(“filename”, “w”)
Explanation: The fopen function with mode “w” is used to open a file in C for writing.
Quiz 36:
In C, what is the purpose of the ‘else’ statement?
- Declare a variable
- Specify an alternative block of code
- Loop through an array
- Terminate the program
Correct Answer: 2. Specify an alternative block of code
Explanation: The ‘else’ statement in C is used to specify an alternative block of code to be executed when the ‘if’ condition is false.
Quiz 37:
Which data type is used to store whole numbers in C?
- int
- float
- char
- double
Correct Answer: 1. int
Explanation: The int data type is used to store whole numbers in C.
Quiz 38:
What is the purpose of the ‘free’ function in C?
- Allocate memory dynamically
- Initialize memory to zero
- Deallocate memory
- Allocate memory for an array of elements
Correct Answer: 3. Deallocate memory
Explanation: The ‘free’ function in C is used to deallocate memory that was previously allocated dynamically using functions like ‘malloc’ or ‘calloc’.
Quiz 39:
Which header file should be included to use the ‘strlen’ function in C?
- string.h
- stdio.h
- stdlib.h
- math.h
Correct Answer: 1. string.h
Explanation: The ‘strlen’ function is part of the string manipulation functions in C, and the header file string.h should be included.
Quiz 40:
What is the purpose of the ‘goto’ statement in C?
- Exit the program
- Jump to a specified label within the program
- Make decisions based on a condition
- Loop through an array
Correct Answer: 2. Jump to a specified label within the program
Explanation: The ‘goto’ statement in C is used to transfer control to a specified label within the program.
Quiz 41:
Which operator is used for bitwise left shift in C?
- <<
- >>
- &
- |
Correct Answer: 1. <<
Explanation: The << operator is used for bitwise left shift in C, which shifts the bits to the left.
Quiz 42:
What is the role of the ‘include’ directive in C?
- Define a new function
- Include external files in the program
- Declare a variable
- Print a message
Correct Answer: 2. Include external files in the program
Explanation: The ‘include’ directive in C is used to include external files in the program, often header files containing declarations.
Quiz 43:
Which of the following is the correct syntax for a function declaration in C?
- function MyFunction() { /* code */ }
- def MyFunction(): pass
- void MyFunction() { /* code */ }
- int MyFunction(int param);
Correct Answer: 4. int MyFunction(int param);
Explanation: The correct syntax for a function declaration in C includes the return type, function name, and parameter list.
Quiz 44:
What is the purpose of the ‘switch’ statement in C?
- Loop through a range of values
- Make decisions based on multiple conditions
- Create an infinite loop
- Define a constant value
Correct Answer: 2. Make decisions based on multiple conditions
Explanation: The ‘switch’ statement in C is used to make decisions based on the values of an expression.
Quiz 45:
Which of the following is the correct way to declare a pointer in C?
- int ptr;
- pointer int;
- int *ptr;
- ptr int;
Correct Answer: 3. int *ptr;
Explanation: The correct way to declare a pointer in C is by placing the asterisk (*) before the variable name.
Quiz 46:
In C, what is the role of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 47:
Which function is used to convert a string to an integer in C?
- atoi()
- itoa()
- strtoi()
- intToStr()
Correct Answer: 1. atoi()
Explanation: The atoi() function in C is used to convert a string to an integer.
Quiz 48:
What is the purpose of the ‘const’ keyword in a function declaration in C?
- Specify the return type
- Declare a constant variable
- Define a constant value
- Indicate a variable parameter
Correct Answer: 4. Indicate a variable parameter
Explanation: The ‘const’ keyword in a function declaration is used to indicate that a parameter is a constant.
Quiz 49:
Which of the following is a valid way to initialize an array in C?
- int myArray = {1, 2, 3};
- int myArray[] = {1, 2, 3};
- myArray = {1, 2, 3};
- int myArray[3] = {1, 2, 3};
Correct Answer: 2. int myArray[] = {1, 2, 3};
Explanation: The correct syntax for initializing an array in C is to use curly braces {} with the values enclosed.
Quiz 50:
What is the purpose of the ‘volatile’ keyword in C?
- Declare a constant value
- Specify the return type of a function
- Indicate that a variable may be changed at any time
- Create a dynamic variable
Correct Answer: 3. Indicate that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 51:
Which function is used to write a character to the standard output in C?
- putchar()
- writechar()
- printchar()
- displaychar()
Correct Answer: 1. putchar()
Explanation: The putchar() function in C is used to write a character to the standard output (usually the console).
Quiz 52:
What is the purpose of the ‘rand()’ function in C?
- Allocate memory dynamically
- Generate a random number
- Return the square root of a number
- Convert a string to uppercase
Correct Answer: 2. Generate a random number
Explanation: The ‘rand()’ function in C is used to generate a pseudo-random integer.
Quiz 53:
In C, how can you declare a constant variable?
- const var = 5;
- constant int var = 5;
- var const = 5;
- int const var = 5;
Correct Answer: 4. int const var = 5;
Explanation: To declare a constant variable in C, use the ‘const’ keyword before the data type.
Quiz 54:
Which operator is used for pointer arithmetic in C?
- +
- –
- *
- /
Correct Answer: 2. –
Explanation: The – operator is used for pointer arithmetic in C to find the difference between two pointers.
Quiz 55:
What is the purpose of the ‘do-while’ loop in C?
- Iterate over a range of values
- Make decisions based on a condition
- Execute a block of code at least once
- Create an infinite loop
Correct Answer: 3. Execute a block of code at least once
Explanation: The ‘do-while’ loop in C ensures that the code block is executed at least once, even if the condition is false.
Quiz 56:
Which header file should be included to use the ‘abs’ function in C for absolute value?
- stdlib.h
- math.h
- stdio.h
- limits.h
Correct Answer: 1. stdlib.h
Explanation: The ‘abs’ function for absolute value is part of the stdlib.h (standard library) in C.
Quiz 57:
What does the ‘static’ keyword do when applied to a variable in C?
- Allocates memory dynamically
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
Correct Answer: 3. Extends the variable’s scope to the entire program
Explanation: The ‘static’ keyword, when applied to a variable in C, extends its scope to the entire program.
Quiz 58:
Which of the following is a valid way to open a file in C for reading and writing?
- fopen(“file.txt”, “r”)
- fopen(“file.txt”, “w”)
- fopen(“file.txt”, “rw”)
- fopen(“file.txt”, “a+”)
Correct Answer: 4. fopen(“file.txt”, “a+”)
Explanation: The mode “a+” in fopen is used to open a file in C for reading and writing, with the file positioned at the end initially.
Quiz 59:
What is the purpose of the ‘continue’ statement in a loop in C?
- Skip the current iteration and move to the next
- Exit the loop
- Terminate the program
- Restart the loop from the beginning
Correct Answer: 1. Skip the current iteration and move to the next
Explanation: The ‘continue’ statement in C is used to skip the rest of the code inside a loop for the current iteration and move to the next one.
Quiz 60:
Which data type is used to store decimal numbers with single precision in C?
- float
- double
- long double
- decimal
Correct Answer: 1. float
Explanation: The float data type in C is used to store decimal numbers with single precision.
Quiz 61:
Which header file should be included to use the ‘pow’ function in C for exponentiation?
- math.h
- stdio.h
- stdlib.h
- power.h
Correct Answer: 1. math.h
Explanation: The ‘pow’ function for exponentiation is part of the math.h (mathematics) library in C.
Quiz 62:
What is the purpose of the ‘getchar’ function in C?
- Read a character from the standard input
- Print a character to the standard output
- Return a character from a function
- Initialize a character variable
Correct Answer: 1. Read a character from the standard input
Explanation: The getchar function in C is used to read a single character from the standard input (usually the keyboard).
Quiz 63:
In C, what is the purpose of the ‘sizeof’ operator when used with a data type?
- Return the size of a variable
- Return the size of a constant
- Return the size of a pointer
- Return the size of the specified data type
Correct Answer: 4. Return the size of the specified data type
Explanation: The ‘sizeof’ operator in C, when used with a data type, returns the size, in bytes, of the specified data type.
Quiz 64:
Which operator is used for logical OR in C?
- &&
- ||
- !
- |
Correct Answer: 2. ||
Explanation: The || operator is used for logical OR in C.
Quiz 65:
What is the purpose of the ‘fwrite’ function in C?
- Read from a file
- Write to a file
- Copy one file to another
- Close a file
Correct Answer: 2. Write to a file
Explanation: The ‘fwrite’ function in C is used to write data to a file.
Quiz 66:
Which function is used to convert a character to its ASCII value in C?
- charToAscii()
- asciify()
- char()
- int()
Correct Answer: 4. int()
Explanation: To convert a character to its ASCII value in C, you can use an explicit type cast like int(character).
Quiz 67:
What is the purpose of the ‘strcat’ function in C?
- Compare two strings
- Copy one string to another
- Concatenate two strings
- Find the length of a string
Correct Answer: 3. Concatenate two strings
Explanation: The ‘strcat’ function in C is used to concatenate (append) two strings.
Quiz 68:
Which of the following is the correct syntax for declaring a structure in C?
- struct MyStruct { /* members */ };
- structure MyStruct { /* members */ };
- type MyStruct { /* members */ };
- new struct MyStruct { /* members */ };
Correct Answer: 1. struct MyStruct { /* members */ };
Explanation: The correct syntax for declaring a structure in C is struct MyStruct { /* members */ };.
Quiz 69:
What does the ‘volatile’ keyword do when applied to a variable in C?
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
- Indicates that a variable may be changed at any time
Correct Answer: 4. Indicates that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 70:
Which operator is used for pointer dereferencing in C?
- *
- &
- ->
- %
Correct Answer: 1. *
Explanation: The * operator is used for pointer dereferencing in C.
Quiz 71:
What is the purpose of the ‘const’ keyword in C when applied to a pointer?
- Indicates a constant value
- Specifies that the pointer cannot be modified
- Declares a constant pointer
- Specifies that the pointed-to value is constant
Correct Answer: 4. Specifies that the pointed-to value is constant
Explanation: When ‘const’ is applied to a pointer in C, it indicates that the pointed-to value is constant and cannot be modified through that pointer.
Quiz 72:
Which function is used to allocate memory for an array dynamically in C?
- malloc()
- calloc()
- realloc()
- alloc()
Correct Answer: 2. calloc()
Explanation: The calloc() function in C is used to dynamically allocate memory for an array and initializes the allocated memory to zero.
Quiz 73:
What is the purpose of the ‘strlen’ function in C?
- Concatenate two strings
- Compare two strings
- Find the length of a string
- Copy one string to another
Correct Answer: 3. Find the length of a string
Explanation: The ‘strlen’ function in C is used to determine the length (number of characters) of a string.
Quiz 74:
Which operator is used for bitwise AND in C?
- &
- |
- ^
- <<
Correct Answer: 1. &
Explanation: The & operator is used for bitwise AND in C.
Quiz 75:
What is the purpose of the ‘return’ statement in a function in C?
- Exit the program
- Return a value from the function
- Declare a variable
- Print a message
Correct Answer: 2. Return a value from the function
Explanation: The ‘return’ statement in C is used to send a value back from a function.
Quiz 76:
Which function is used to close a file in C?
- fclose()
- close()
- fileclose()
- shutfile()
Correct Answer: 1. fclose()
Explanation: The fclose() function is used to close a file in C after performing file operations.
Quiz 77:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 78:
What is the purpose of the ‘typedef’ keyword in C?
- Declare a new type name
- Define a constant value
- Specify the return type of a function
- Create an alias for a variable
Correct Answer: 1. Declare a new type name
Explanation: The ‘typedef’ keyword in C is used to create a new type name for an existing data type.
Quiz 79:
Which of the following is the correct syntax for a function definition in C?
- def myFunction(): pass
- int myFunction() { /* code */ }
- void myFunction() { /* code */ }
- int myFunction(parameters) { /* code */ }
Correct Answer: 4. int myFunction(parameters) { /* code */ }
Explanation: The correct syntax for a function definition in C includes the return type, function name, parameters, and the function body.
Quiz 80:
What is the purpose of the ‘union’ keyword in C?
- Declare a new type name
- Represent a collection of variables
- Create an empty function
- Allocate memory dynamically
Correct Answer: 2. Represent a collection of variables
Explanation: The ‘union’ keyword in C is used to represent a collection of variables that share the same memory location.
Quiz 81:
Which header file should be included to use the ‘scanf’ function in C?
- input.h
- output.h
- stdio.h
- stdlib.h
Correct Answer: 3. stdio.h
Explanation: The ‘scanf’ function is part of the Standard Input/Output library in C, and the header file stdio.h should be included.
Quiz 82:
What is the purpose of the ‘for’ loop in C?
- Execute a block of code at least once
- Iterate over a range of values
- Make decisions based on a condition
- Skip the current iteration and move to the next
Correct Answer: 2. Iterate over a range of values
Explanation: The ‘for’ loop in C is used to iterate over a range of values with a specified control structure.
Quiz 83:
Which operator is used for the modulo operation in C?
- %
- &
- |
- ^
Correct Answer: 1. %
Explanation: The % operator is used for the modulo operation in C, which returns the remainder of a division.
Quiz 84:
What does the ‘sizeof’ operator return when used with a pointer in C?
- Size of the pointer variable
- Size of the data type to which the pointer points
- Total size of the memory allocated for the pointer
- Size of the memory address held by the pointer
Correct Answer: 1. Size of the pointer variable
Explanation: When used with a pointer, the ‘sizeof’ operator in C returns the size of the pointer variable.
Quiz 85:
Which function is used to open a file in C for writing?
- fopen(“filename”, “r”)
- fopen(“filename”, “w”)
- fopen(“filename”, “a”)
- fopen(“filename”, “rb”)
Correct Answer: 2. fopen(“filename”, “w”)
Explanation: The fopen function with mode “w” is used to open a file in C for writing.
Quiz 86:
In C, what is the purpose of the ‘else’ statement?
- Declare a variable
- Specify an alternative block of code
- Loop through an array
- Terminate the program
Correct Answer: 2. Specify an alternative block of code
Explanation: The ‘else’ statement in C is used to specify an alternative block of code to be executed when the ‘if’ condition is false.
Quiz 87:
Which data type is used to store whole numbers in C?
- int
- float
- char
- double
Correct Answer: 1. int
Explanation: The int data type is used to store whole numbers in C.
Quiz 88:
What is the purpose of the ‘free’ function in C?
- Allocate memory dynamically
- Initialize memory to zero
- Deallocate memory
- Allocate memory for an array of elements
Correct Answer: 3. Deallocate memory
Explanation: The ‘free’ function in C is used to deallocate memory that was previously allocated dynamically using functions like ‘malloc’ or ‘calloc’.
Quiz 89:
Which header file should be included to use the ‘strlen’ function in C?
- string.h
- stdio.h
- stdlib.h
- math.h
Correct Answer: 1. string.h
Explanation: The ‘strlen’ function is part of the string manipulation functions in C, and the header file string.h should be included.
Quiz 90:
What is the purpose of the ‘goto’ statement in C?
- Exit the program
- Jump to a specified label within the program
- Make decisions based on a condition
- Loop through an array
Correct Answer: 2. Jump to a specified label within the program
Explanation: The ‘goto’ statement in C is used to transfer control to a specified label within the program.
Quiz 91:
Which operator is used for bitwise left shift in C?
- <<
- >>
- &
- |
Correct Answer: 1. <<
Explanation: The << operator is used for bitwise left shift in C, which shifts the bits to the left.
Quiz 92:
What is the role of the ‘include’ directive in C?
- Define a new function
- Include external files in the program
- Declare a variable
- Print a message
Correct Answer: 2. Include external files in the program
Explanation: The ‘include’ directive in C is used to include external files in the program, often header files containing declarations.
Quiz 93:
Which of the following is the correct syntax for a function declaration in C?
- function MyFunction() { /* code */ }
- def MyFunction(): pass
- void MyFunction() { /* code */ }
- int MyFunction(int param);
Correct Answer: 4. int MyFunction(int param);
Explanation: The correct syntax for a function declaration in C includes the return type, function name, and parameter list.
Quiz 94:
What is the purpose of the ‘switch’ statement in C?
- Loop through a range of values
- Make decisions based on multiple conditions
- Create an infinite loop
- Define a constant value
Correct Answer: 2. Make decisions based on multiple conditions
Explanation: The ‘switch’ statement in C is used to make decisions based on the values of an expression.
Quiz 95:
Which of the following is the correct way to declare a pointer in C?
- int ptr;
- pointer int;
- int *ptr;
- ptr int;
Correct Answer: 3. int *ptr;
Explanation: The correct way to declare a pointer in C is by placing the asterisk (*) before the variable name.
Quiz 96:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 97:
Which function is used to convert a string to an integer in C?
- atoi()
- itoa()
- strtoi()
- intToStr()
Correct Answer: 1. atoi()
Explanation: The atoi() function in C is used to convert a string to an integer.
Quiz 98:
What is the purpose of the ‘const’ keyword in a function declaration in C?
- Specify the return type
- Declare a constant variable
- Define a constant value
- Indicate a variable parameter
Correct Answer: 4. Indicate a variable parameter
Explanation: The ‘const’ keyword in a function declaration is used to indicate that a parameter is a constant.
Quiz 99:
Which of the following is a valid way to initialize an array in C?
- int myArray = {1, 2, 3};
- int myArray[] = {1, 2, 3};
- myArray = {1, 2, 3};
- int myArray[3] = {1, 2, 3};
Correct Answer: 2. int myArray[] = {1, 2, 3};
Explanation: The correct syntax for initializing an array in C is to use curly braces {} with the values enclosed.
Quiz 100:
What is the purpose of the ‘volatile’ keyword in C?
- Declare a constant value
- Specify the return type of a function
- Indicate that a variable may be changed at any time
- Create a dynamic variable
Correct Answer: 3. Indicate that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 101:
Which function is used to write a character to the standard output in C?
- putchar()
- writechar()
- printchar()
- displaychar()
Correct Answer: 1. putchar()
Explanation: The putchar() function in C is used to write a character to the standard output (usually the console).
Quiz 102:
What is the purpose of the ‘rand()’ function in C?
- Allocate memory dynamically
- Generate a random number
- Return the square root of a number
- Convert a string to uppercase
Correct Answer: 2. Generate a random number
Explanation: The ‘rand()’ function in C is used to generate a pseudo-random integer.
Quiz 103:
In C, how can you declare a constant variable?
- const var = 5;
- constant int var = 5;
- var const = 5;
- int const var = 5;
Correct Answer: 4. int const var = 5;
Explanation: To declare a constant variable in C, use the ‘const’ keyword before the data type.
Quiz 104:
Which operator is used for pointer arithmetic in C?
- +
- –
- *
- /
Correct Answer: 2. –
Explanation: The – operator is used for pointer arithmetic in C to find the difference between two pointers.
Quiz 105:
What is the purpose of the ‘do-while’ loop in C?
- Iterate over a range of values
- Make decisions based on a condition
- Execute a block of code at least once
- Create an infinite loop
Correct Answer: 3. Execute a block of code at least once
Explanation: The ‘do-while’ loop in C ensures that the code block is executed at least once, even if the condition is false.
Quiz 106:
Which header file should be included to use the ‘abs’ function in C for absolute value?
- stdlib.h
- math.h
- stdio.h
- limits.h
Correct Answer: 1. stdlib.h
Explanation: The ‘abs’ function for absolute value is part of the stdlib.h (standard library) in C.
Quiz 107:
What does the ‘static’ keyword do when applied to a variable in C?
- Allocates memory dynamically
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
Correct Answer: 3. Extends the variable’s scope to the entire program
Explanation: The ‘static’ keyword, when applied to a variable in C, extends its scope to the entire program.
Quiz 108:
Which of the following is a valid way to open a file in C for reading and writing?
- fopen(“file.txt”, “r”)
- fopen(“file.txt”, “w”)
- fopen(“file.txt”, “rw”)
- fopen(“file.txt”, “a+”)
Correct Answer: 4. fopen(“file.txt”, “a+”)
Explanation: The mode “a+” in fopen is used to open a file in C for reading and writing, with the file positioned at the end initially.
Quiz 109:
What is the purpose of the ‘continue’ statement in a loop in C?
- Skip the current iteration and move to the next
- Exit the loop
- Terminate the program
- Restart the loop from the beginning
Correct Answer: 1. Skip the current iteration and move to the next
Explanation: The ‘continue’ statement in C is used to skip the rest of the code inside a loop for the current iteration and move to the next one.
Quiz 110:
Which data type is used to store decimal numbers with single precision in C?
- float
- double
- long double
- decimal
Correct Answer: 1. float
Explanation: The float data type in C is used to store decimal numbers with single precision.
Quiz 111:
Which header file should be included to use the ‘pow’ function in C for exponentiation?
- math.h
- stdio.h
- stdlib.h
- power.h
Correct Answer: 1. math.h
Explanation: The ‘pow’ function for exponentiation is part of the math.h (mathematics) library in C.
Quiz 112:
What is the purpose of the ‘getchar’ function in C?
- Read a character from the standard input
- Print a character to the standard output
- Return a character from a function
- Initialize a character variable
Correct Answer: 1. Read a character from the standard input
Explanation: The getchar function in C is used to read a single character from the standard input (usually the keyboard).
Quiz 113:
In C, what is the purpose of the ‘sizeof’ operator when used with a data type?
- Return the size of a variable
- Return the size of a constant
- Return the size of a pointer
- Return the size of the specified data type
Correct Answer: 4. Return the size of the specified data type
Explanation: The ‘sizeof’ operator in C, when used with a data type, returns the size, in bytes, of the specified data type.
Quiz 114:
Which operator is used for logical OR in C?
- &&
- ||
- !
- |
Correct Answer: 2. ||
Explanation: The || operator is used for logical OR in C.
Quiz 115:
What is the purpose of the ‘fwrite’ function in C?
- Read from a file
- Write to a file
- Copy one file to another
- Close a file
Correct Answer: 2. Write to a file
Explanation: The ‘fwrite’ function in C is used to write data to a file.
Quiz 116:
Which function is used to convert a character to its ASCII value in C?
- charToAscii()
- asciify()
- char()
- int()
Correct Answer: 4. int()
Explanation: To convert a character to its ASCII value in C, you can use an explicit type cast like int(character).
Quiz 117:
What is the purpose of the ‘strcat’ function in C?
- Compare two strings
- Copy one string to another
- Concatenate two strings
- Find the length of a string
Correct Answer: 3. Concatenate two strings
Explanation: The ‘strcat’ function in C is used to concatenate (append) two strings.
Quiz 118:
Which of the following is the correct syntax for declaring a structure in C?
- struct MyStruct { /* members */ };
- structure MyStruct { /* members */ };
- type MyStruct { /* members */ };
- new struct MyStruct { /* members */ };
Correct Answer: 1. struct MyStruct { /* members */ };
Explanation: The correct syntax for declaring a structure in C is struct MyStruct { /* members */ };.
Quiz 119:
What does the ‘volatile’ keyword do when applied to a variable in C?
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
- Indicates that a variable may be changed at any time
Correct Answer: 4. Indicates that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 120:
Which operator is used for pointer dereferencing in C?
- *
- &
- ->
- %
Correct Answer: 1. *
Explanation: The * operator is used for pointer dereferencing in C.
Quiz 121:
What is the purpose of the ‘const’ keyword in C when applied to a pointer?
- Indicates a constant value
- Specifies that the pointer cannot be modified
- Declares a constant pointer
- Specifies that the pointed-to value is constant
Correct Answer: 4. Specifies that the pointed-to value is constant
Explanation: When ‘const’ is applied to a pointer in C, it indicates that the pointed-to value is constant and cannot be modified through that pointer.
Quiz 122:
Which function is used to allocate memory for an array dynamically in C?
- malloc()
- calloc()
- realloc()
- alloc()
Correct Answer: 2. calloc()
Explanation: The calloc() function in C is used to dynamically allocate memory for an array and initializes the allocated memory to zero.
Quiz 123:
What is the purpose of the ‘strlen’ function in C?
- Concatenate two strings
- Compare two strings
- Find the length of a string
- Copy one string to another
Correct Answer: 3. Find the length of a string
Explanation: The ‘strlen’ function in C is used to determine the length (number of characters) of a string.
Quiz 124:
Which operator is used for bitwise AND in C?
- &
- |
- ^
- <<
Correct Answer: 1. &
Explanation: The & operator is used for bitwise AND in C.
Quiz 125:
What is the purpose of the ‘return’ statement in a function in C?
- Exit the program
- Return a value from the function
- Declare a variable
- Print a message
Correct Answer: 2. Return a value from the function
Explanation: The ‘return’ statement in C is used to send a value back from a function.
Quiz 126:
Which function is used to close a file in C?
- fclose()
- close()
- fileclose()
- shutfile()
Correct Answer: 1. fclose()
Explanation: The fclose() function is used to close a file in C after performing file operations.
Quiz 127:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 128:
What is the purpose of the ‘typedef’ keyword in C?
- Declare a new type name
- Define a constant value
- Specify the return type of a function
- Create an alias for a variable
Correct Answer: 1. Declare a new type name
Explanation: The ‘typedef’ keyword in C is used to create a new type name for an existing data type.
Quiz 129:
Which of the following is the correct syntax for a function definition in C?
- def myFunction(): pass
- int myFunction() { /* code */ }
- void myFunction() { /* code */ }
- int myFunction(parameters) { /* code */ }
Correct Answer: 4. int myFunction(parameters) { /* code */ }
Explanation: The correct syntax for a function definition in C includes the return type, function name, parameters, and the function body.
Quiz 130:
What is the purpose of the ‘union’ keyword in C?
- Declare a new type name
- Represent a collection of variables
- Create an empty function
- Allocate memory dynamically
Correct Answer: 2. Represent a collection of variables
Explanation: The ‘union’ keyword in C is used to represent a collection of variables that share the same memory location.
Quiz 131:
Which header file should be included to use the ‘scanf’ function in C?
- input.h
- output.h
- stdio.h
- stdlib.h
Correct Answer: 3. stdio.h
Explanation: The ‘scanf’ function is part of the Standard Input/Output library in C, and the header file stdio.h should be included.
Quiz 132:
What is the purpose of the ‘for’ loop in C?
- Execute a block of code at least once
- Iterate over a range of values
- Make decisions based on a condition
- Skip the current iteration and move to the next
Correct Answer: 2. Iterate over a range of values
Explanation: The ‘for’ loop in C is used to iterate over a range of values with a specified control structure.
Quiz 133:
Which operator is used for the modulo operation in C?
- %
- &
- |
- ^
Correct Answer: 1. %
Explanation: The % operator is used for the modulo operation in C, which returns the remainder of a division.
Quiz 134:
What does the ‘sizeof’ operator return when used with a pointer in C?
- Size of the pointer variable
- Size of the data type to which the pointer points
- Total size of the memory allocated for the pointer
- Size of the memory address held by the pointer
Correct Answer: 1. Size of the pointer variable
Explanation: When used with a pointer, the ‘sizeof’ operator in C returns the size of the pointer variable.
Quiz 135:
Which function is used to open a file in C for writing?
- fopen(“filename”, “r”)
- fopen(“filename”, “w”)
- fopen(“filename”, “a”)
- fopen(“filename”, “rb”)
Correct Answer: 2. fopen(“filename”, “w”)
Explanation: The fopen function with mode “w” is used to open a file in C for writing.
Quiz 136:
In C, what is the purpose of the ‘else’ statement?
- Declare a variable
- Specify an alternative block of code
- Loop through an array
- Terminate the program
Correct Answer: 2. Specify an alternative block of code
Explanation: The ‘else’ statement in C is used to specify an alternative block of code to be executed when the ‘if’ condition is false.
Quiz 137:
Which data type is used to store whole numbers in C?
- int
- float
- char
- double
Correct Answer: 1. int
Explanation: The int data type is used to store whole numbers in C.
Quiz 138:
What is the purpose of the ‘free’ function in C?
- Allocate memory dynamically
- Initialize memory to zero
- Deallocate memory
- Allocate memory for an array of elements
Correct Answer: 3. Deallocate memory
Explanation: The ‘free’ function in C is used to deallocate memory that was previously allocated dynamically using functions like ‘malloc’ or ‘calloc’.
Quiz 139:
Which header file should be included to use the ‘strlen’ function in C?
- string.h
- stdio.h
- stdlib.h
- math.h
Correct Answer: 1. string.h
Explanation: The ‘strlen’ function is part of the string manipulation functions in C, and the header file string.h should be included.
Quiz 140:
What is the purpose of the ‘goto’ statement in C?
- Exit the program
- Jump to a specified label within the program
- Make decisions based on a condition
- Loop through an array
Correct Answer: 2. Jump to a specified label within the program
Explanation: The ‘goto’ statement in C is used to transfer control to a specified label within the program.
Quiz 141:
Which operator is used for bitwise left shift in C?
- <<
- >>
- &
- |
Correct Answer: 1. <<
Explanation: The << operator is used for bitwise left shift in C, which shifts the bits to the left.
Quiz 142:
What is the role of the ‘include’ directive in C?
- Define a new function
- Include external files in the program
- Declare a variable
- Print a message
Correct Answer: 2. Include external files in the program
Explanation: The ‘include’ directive in C is used to include external files in the program, often header files containing declarations.
Quiz 143:
Which of the following is the correct syntax for a function declaration in C?
- function MyFunction() { /* code */ }
- def MyFunction(): pass
- void MyFunction() { /* code */ }
- int MyFunction(int param);
Correct Answer: 4. int MyFunction(int param);
Explanation: The correct syntax for a function declaration in C includes the return type, function name, and parameter list.
Quiz 144:
What is the purpose of the ‘switch’ statement in C?
- Loop through a range of values
- Make decisions based on multiple conditions
- Create an infinite loop
- Define a constant value
Correct Answer: 2. Make decisions based on multiple conditions
Explanation: The ‘switch’ statement in C is used to make decisions based on the values of an expression.
Quiz 145:
Which of the following is the correct way to declare a pointer in C?
- int ptr;
- pointer int;
- int *ptr;
- ptr int;
Correct Answer: 3. int *ptr;
Explanation: The correct way to declare a pointer in C is by placing the asterisk (*) before the variable name.
Quiz 146:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 147:
Which function is used to convert a string to an integer in C?
- atoi()
- itoa()
- strtoi()
- intToStr()
Correct Answer: 1. atoi()
Explanation: The atoi() function in C is used to convert a string to an integer.
Quiz 148:
What is the purpose of the ‘const’ keyword in a function declaration in C?
- Specify the return type
- Declare a constant variable
- Define a constant value
- Indicate a variable parameter
Correct Answer: 4. Indicate a variable parameter
Explanation: The ‘const’ keyword in a function declaration is used to indicate that a parameter is a constant.
Quiz 149:
Which of the following is a valid way to initialize an array in C?
- int myArray = {1, 2, 3};
- int myArray[] = {1, 2, 3};
- myArray = {1, 2, 3};
- int myArray[3] = {1, 2, 3};
Correct Answer: 2. int myArray[] = {1, 2, 3};
Explanation: The correct syntax for initializing an array in C is to use curly braces {} with the values enclosed.
Quiz 150:
What is the purpose of the ‘volatile’ keyword in C?
- Declare a constant value
- Specify the return type of a function
- Indicate that a variable may be changed at any time
- Create a dynamic variable
Correct Answer: 3. Indicate that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 151:
Which function is used to write a character to the standard output in C?
- putchar()
- writechar()
- printchar()
- displaychar()
Correct Answer: 1. putchar()
Explanation: The putchar() function in C is used to write a character to the standard output (usually the console).
Quiz 152:
What is the purpose of the ‘rand()’ function in C?
- Allocate memory dynamically
- Generate a random number
- Return the square root of a number
- Convert a string to uppercase
Correct Answer: 2. Generate a random number
Explanation: The ‘rand()’ function in C is used to generate a pseudo-random integer.
Quiz 153:
In C, how can you declare a constant variable?
- const var = 5;
- constant int var = 5;
- var const = 5;
- int const var = 5;
Correct Answer: 4. int const var = 5;
Explanation: To declare a constant variable in C, use the ‘const’ keyword before the data type.
Quiz 154:
Which operator is used for pointer arithmetic in C?
- +
- –
- *
- /
Correct Answer: 2. –
Explanation: The – operator is used for pointer arithmetic in C to find the difference between two pointers.
Quiz 155:
What is the purpose of the ‘do-while’ loop in C?
- Iterate over a range of values
- Make decisions based on a condition
- Execute a block of code at least once
- Create an infinite loop
Correct Answer: 3. Execute a block of code at least once
Explanation: The ‘do-while’ loop in C ensures that the code block is executed at least once, even if the condition is false.
Quiz 156:
Which header file should be included to use the ‘abs’ function in C for absolute value?
- stdlib.h
- math.h
- stdio.h
- limits.h
Correct Answer: 1. stdlib.h
Explanation: The ‘abs’ function for absolute value is part of the stdlib.h (standard library) in C.
Quiz 157:
What does the ‘static’ keyword do when applied to a variable in C?
- Allocates memory dynamically
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
Correct Answer: 3. Extends the variable’s scope to the entire program
Explanation: The ‘static’ keyword, when applied to a variable in C, extends its scope to the entire program.
Quiz 158:
Which of the following is a valid way to open a file in C for reading and writing?
- fopen(“file.txt”, “r”)
- fopen(“file.txt”, “w”)
- fopen(“file.txt”, “rw”)
- fopen(“file.txt”, “a+”)
Correct Answer: 4. fopen(“file.txt”, “a+”)
Explanation: The mode “a+” in fopen is used to open a file in C for reading and writing, with the file positioned at the end initially.
Quiz 159:
What is the purpose of the ‘continue’ statement in a loop in C?
- Skip the current iteration and move to the next
- Exit the loop
- Terminate the program
- Restart the loop from the beginning
Correct Answer: 1. Skip the current iteration and move to the next
Explanation: The ‘continue’ statement in C is used to skip the rest of the code inside a loop for the current iteration and move to the next one.
Quiz 160:
Which data type is used to store decimal numbers with single precision in C?
- float
- double
- long double
- decimal
Correct Answer: 1. float
Explanation: The float data type in C is used to store decimal numbers with single precision.
Quiz 161:
Which header file should be included to use the ‘pow’ function in C for exponentiation?
- math.h
- stdio.h
- stdlib.h
- power.h
Correct Answer: 1. math.h
Explanation: The ‘pow’ function for exponentiation is part of the math.h (mathematics) library in C.
Quiz 162:
What is the purpose of the ‘getchar’ function in C?
- Read a character from the standard input
- Print a character to the standard output
- Return a character from a function
- Initialize a character variable
Correct Answer: 1. Read a character from the standard input
Explanation: The getchar function in C is used to read a single character from the standard input (usually the keyboard).
Quiz 163:
In C, what is the purpose of the ‘sizeof’ operator when used with a data type?
- Return the size of a variable
- Return the size of a constant
- Return the size of a pointer
- Return the size of the specified data type
Correct Answer: 4. Return the size of the specified data type
Explanation: The ‘sizeof’ operator in C, when used with a data type, returns the size, in bytes, of the specified data type.
Quiz 164:
Which operator is used for logical OR in C?
- &&
- ||
- !
- |
Correct Answer: 2. ||
Explanation: The || operator is used for logical OR in C.
Quiz 165:
What is the purpose of the ‘fwrite’ function in C?
- Read from a file
- Write to a file
- Copy one file to another
- Close a file
Correct Answer: 2. Write to a file
Explanation: The ‘fwrite’ function in C is used to write data to a file.
Quiz 166:
Which function is used to convert a character to its ASCII value in C?
- charToAscii()
- asciify()
- char()
- int()
Correct Answer: 4. int()
Explanation: To convert a character to its ASCII value in C, you can use an explicit type cast like int(character).
Quiz 167:
What is the purpose of the ‘strcat’ function in C?
- Compare two strings
- Copy one string to another
- Concatenate two strings
- Find the length of a string
Correct Answer: 3. Concatenate two strings
Explanation: The ‘strcat’ function in C is used to concatenate (append) two strings.
Quiz 168:
Which of the following is the correct syntax for declaring a structure in C?
- struct MyStruct { /* members */ };
- structure MyStruct { /* members */ };
- type MyStruct { /* members */ };
- new struct MyStruct { /* members */ };
Correct Answer: 1. struct MyStruct { /* members */ };
Explanation: The correct syntax for declaring a structure in C is struct MyStruct { /* members */ };.
Quiz 169:
What does the ‘volatile’ keyword do when applied to a variable in C?
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
- Indicates that a variable may be changed at any time
Correct Answer: 4. Indicates that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 170:
Which operator is used for pointer dereferencing in C?
- *
- &
- ->
- %
Correct Answer: 1. *
Explanation: The * operator is used for pointer dereferencing in C.
Quiz 171:
What is the purpose of the ‘const’ keyword in C when applied to a pointer?
- Indicates a constant value
- Specifies that the pointer cannot be modified
- Declares a constant pointer
- Specifies that the pointed-to value is constant
Correct Answer: 4. Specifies that the pointed-to value is constant
Explanation: When ‘const’ is applied to a pointer in C, it indicates that the pointed-to value is constant and cannot be modified through that pointer.
Quiz 172:
Which function is used to allocate memory for an array dynamically in C?
- malloc()
- calloc()
- realloc()
- alloc()
Correct Answer: 2. calloc()
Explanation: The calloc() function in C is used to dynamically allocate memory for an array and initializes the allocated memory to zero.
Quiz 173:
What is the purpose of the ‘strlen’ function in C?
- Concatenate two strings
- Compare two strings
- Find the length of a string
- Copy one string to another
Correct Answer: 3. Find the length of a string
Explanation: The ‘strlen’ function in C is used to determine the length (number of characters) of a string.
Quiz 174:
Which operator is used for bitwise AND in C?
- &
- |
- ^
- <<
Correct Answer: 1. &
Explanation: The & operator is used for bitwise AND in C.
Quiz 175:
What is the purpose of the ‘return’ statement in a function in C?
- Exit the program
- Return a value from the function
- Declare a variable
- Print a message
Correct Answer: 2. Return a value from the function
Explanation: The ‘return’ statement in C is used to send a value back from a function.
Quiz 176:
Which function is used to close a file in C?
- fclose()
- close()
- fileclose()
- shutfile()
Correct Answer: 1. fclose()
Explanation: The fclose() function is used to close a file in C after performing file operations.
Quiz 177:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 178:
What is the purpose of the ‘typedef’ keyword in C?
- Declare a new type name
- Define a constant value
- Specify the return type of a function
- Create an alias for a variable
Correct Answer: 1. Declare a new type name
Explanation: The ‘typedef’ keyword in C is used to create a new type name for an existing data type.
Quiz 179:
Which of the following is the correct syntax for declaring a function in C?
- def myFunction(): pass
- int myFunction() { /* code */ }
- void myFunction() { /* code */ }
- int myFunction(parameters) { /* code */ }
Correct Answer: 4. int myFunction(parameters) { /* code */ }
Explanation: The correct syntax for a function declaration in C includes the return type, function name, parameters, and the function body.
Quiz 180:
What is the purpose of the ‘union’ keyword in C?
- Declare a new type name
- Represent a collection of variables
- Create an empty function
- Allocate memory dynamically
Correct Answer: 2. Represent a collection of variables
Explanation: The ‘union’ keyword in C is used to represent a collection of variables that share the same memory location.
Quiz 181:
Which header file should be included to use the ‘scanf’ function in C?
- input.h
- output.h
- stdio.h
- stdlib.h
Correct Answer: 3. stdio.h
Explanation: The ‘scanf’ function is part of the Standard Input/Output library in C, and the header file stdio.h should be included.
Quiz 182:
What is the purpose of the ‘for’ loop in C?
- Execute a block of code at least once
- Iterate over a range of values
- Make decisions based on a condition
- Skip the current iteration and move to the next
Correct Answer: 2. Iterate over a range of values
Explanation: The ‘for’ loop in C is used to iterate over a range of values with a specified control structure.
Quiz 183:
Which operator is used for the modulo operation in C?
- %
- &
- |
- ^
Correct Answer: 1. %
Explanation: The % operator is used for the modulo operation in C, which returns the remainder of a division.
Quiz 184:
What does the ‘sizeof’ operator return when used with a pointer in C?
- Size of the pointer variable
- Size of the data type to which the pointer points
- Total size of the memory allocated for the pointer
- Size of the memory address held by the pointer
Correct Answer: 1. Size of the pointer variable
Explanation: When used with a pointer, the ‘sizeof’ operator in C returns the size of the pointer variable.
Quiz 185:
Which function is used to open a file in C for writing?
- fopen(“filename”, “r”)
- fopen(“filename”, “w”)
- fopen(“filename”, “a”)
- fopen(“filename”, “rb”)
Correct Answer: 2. fopen(“filename”, “w”)
Explanation: The fopen function with mode “w” is used to open a file in C for writing.
Quiz 186:
In C, what is the purpose of the ‘else’ statement?
- Declare a variable
- Specify an alternative block of code
- Loop through an array
- Terminate the program
Correct Answer: 2. Specify an alternative block of code
Explanation: The ‘else’ statement in C is used to specify an alternative block of code to be executed when the ‘if’ condition is false.
Quiz 187:
Which data type is used to store whole numbers in C?
- int
- float
- char
- double
Correct Answer: 1. int
Explanation: The int data type is used to store whole numbers in C.
Quiz 188:
What is the purpose of the ‘free’ function in C?
- Allocate memory dynamically
- Initialize memory to zero
- Deallocate memory
- Allocate memory for an array of elements
Correct Answer: 3. Deallocate memory
Explanation: The ‘free’ function in C is used to deallocate memory that was previously allocated dynamically using functions like ‘malloc’ or ‘calloc’.
Quiz 189:
Which header file should be included to use the ‘strlen’ function in C?
- string.h
- stdio.h
- stdlib.h
- math.h
Correct Answer: 1. string.h
Explanation: The ‘strlen’ function is part of the string manipulation functions in C, and the header file string.h should be included.
Quiz 190:
What is the purpose of the ‘goto’ statement in C?
- Exit the program
- Jump to a specified label within the program
- Make decisions based on a condition
- Loop through an array
Correct Answer: 2. Jump to a specified label within the program
Explanation: The ‘goto’ statement in C is used to transfer control to a specified label within the program.
Quiz 191:
Which operator is used for bitwise left shift in C?
- <<
- >>
- &
- |
Correct Answer: 1. <<
Explanation: The << operator is used for bitwise left shift in C, which shifts the bits to the left.
Quiz 192:
What is the role of the ‘include’ directive in C?
- Define a new function
- Include external files in the program
- Declare a variable
- Print a message
Correct Answer: 2. Include external files in the program
Explanation: The ‘include’ directive in C is used to include external files in the program, often header files containing declarations.
Quiz 193:
Which of the following is the correct syntax for a function declaration in C?
- function MyFunction() { /* code */ }
- def MyFunction(): pass
- void MyFunction() { /* code */ }
- int MyFunction(int param);
Correct Answer: 4. int MyFunction(int param);
Explanation: The correct syntax for a function declaration in C includes the return type, function name, and parameter list.
Quiz 194:
What is the purpose of the ‘switch’ statement in C?
- Loop through a range of values
- Make decisions based on multiple conditions
- Create an infinite loop
- Define a constant value
Correct Answer: 2. Make decisions based on multiple conditions
Explanation: The ‘switch’ statement in C is used to make decisions based on the values of an expression.
Quiz 195:
Which of the following is the correct way to declare a pointer in C?
- int ptr;
- pointer int;
- int *ptr;
- ptr int;
Correct Answer: 3. int *ptr;
Explanation: The correct way to declare a pointer in C is by placing the asterisk (*) before the variable name.
Quiz 196:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 197:
Which function is used to convert a string to an integer in C?
- atoi()
- itoa()
- strtoi()
- intToStr()
Correct Answer: 1. atoi()
Explanation: The atoi() function in C is used to convert a string to an integer.
Quiz 198:
What is the purpose of the ‘const’ keyword in a function declaration in C?
- Specify the return type
- Declare a constant variable
- Define a constant value
- Indicate a variable parameter
Correct Answer: 4. Indicate a variable parameter
Explanation: The ‘const’ keyword in a function declaration is used to indicate that a parameter is a constant.
Quiz 199:
Which of the following is a valid way to initialize an array in C?
- int myArray = {1, 2, 3};
- int myArray[] = {1, 2, 3};
- myArray = {1, 2, 3};
- int myArray[3] = {1, 2, 3};
Correct Answer: 2. int myArray[] = {1, 2, 3};
Explanation: The correct syntax for initializing an array in C is to use curly braces {} with the values enclosed.
Quiz 200:
What is the purpose of the ‘volatile’ keyword in C?
- Declare a constant value
- Specify the return type of a function
- Indicate that a variable may be changed at any time
- Create a dynamic variable
Correct Answer: 3. Indicate that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 201:
Which function is used to write a character to the standard output in C?
- putchar()
- writechar()
- printchar()
- displaychar()
Correct Answer: 1. putchar()
Explanation: The putchar() function in C is used to write a character to the standard output (usually the console).
Quiz 202:
What is the purpose of the ‘rand()’ function in C?
- Allocate memory dynamically
- Generate a random number
- Return the square root of a number
- Convert a string to uppercase
Correct Answer: 2. Generate a random number
Explanation: The ‘rand()’ function in C is used to generate a pseudo-random integer.
Quiz 203:
In C, how can you declare a constant variable?
- const var = 5;
- constant int var = 5;
- var const = 5;
- int const var = 5;
Correct Answer: 4. int const var = 5;
Explanation: To declare a constant variable in C, use the ‘const’ keyword before the data type.
Quiz 204:
Which operator is used for pointer arithmetic in C?
- +
- –
- *
- /
Correct Answer: 2. –
Explanation: The – operator is used for pointer arithmetic in C to find the difference between two pointers.
Quiz 205:
What is the purpose of the ‘do-while’ loop in C?
- Iterate over a range of values
- Make decisions based on a condition
- Execute a block of code at least once
- Create an infinite loop
Correct Answer: 3. Execute a block of code at least once
Explanation: The ‘do-while’ loop in C ensures that the code block is executed at least once, even if the condition is false.
Quiz 206:
Which header file should be included to use the ‘abs’ function in C for absolute value?
- stdlib.h
- math.h
- stdio.h
- limits.h
Correct Answer: 1. stdlib.h
Explanation: The ‘abs’ function for absolute value is part of the stdlib.h (standard library) in C.
Quiz 207:
What does the ‘static’ keyword do when applied to a variable in C?
- Allocates memory dynamically
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
Correct Answer: 3. Extends the variable’s scope to the entire program
Explanation: The ‘static’ keyword, when applied to a variable in C, extends its scope to the entire program.
Quiz 208:
Which of the following is a valid way to open a file in C for reading and writing?
- fopen(“file.txt”, “r”)
- fopen(“file.txt”, “w”)
- fopen(“file.txt”, “rw”)
- fopen(“file.txt”, “a+”)
Correct Answer: 4. fopen(“file.txt”, “a+”)
Explanation: The mode “a+” in fopen is used to open a file in C for reading and writing, with the file positioned at the end initially.
Quiz 209:
What is the purpose of the ‘continue’ statement in a loop in C?
- Skip the current iteration and move to the next
- Exit the loop
- Terminate the program
- Restart the loop from the beginning
Correct Answer: 1. Skip the current iteration and move to the next
Explanation: The ‘continue’ statement in C is used to skip the rest of the code inside a loop for the current iteration and move to the next one.
Quiz 210:
Which data type is used to store decimal numbers with single precision in C?
- float
- double
- long double
- decimal
Correct Answer: 1. float
Explanation: The float data type in C is used to store decimal numbers with single precision.
Quiz 211:
Which header file should be included to use the ‘pow’ function in C for exponentiation?
- math.h
- stdio.h
- stdlib.h
- power.h
Correct Answer: 1. math.h
Explanation: The ‘pow’ function for exponentiation is part of the math.h (mathematics) library in C.
Quiz 212:
What is the purpose of the ‘getchar’ function in C?
- Read a character from the standard input
- Print a character to the standard output
- Return a character from a function
- Initialize a character variable
Correct Answer: 1. Read a character from the standard input
Explanation: The getchar function in C is used to read a single character from the standard input (usually the keyboard).
Quiz 213:
In C, what is the purpose of the ‘sizeof’ operator when used with a data type?
- Return the size of a variable
- Return the size of a constant
- Return the size of a pointer
- Return the size of the specified data type
Correct Answer: 4. Return the size of the specified data type
Explanation: The ‘sizeof’ operator in C, when used with a data type, returns the size, in bytes, of the specified data type.
Quiz 214:
Which operator is used for logical OR in C?
- &&
- ||
- !
- |
Correct Answer: 2. ||
Explanation: The || operator is used for logical OR in C.
Quiz 215:
What is the purpose of the ‘fwrite’ function in C?
- Read from a file
- Write to a file
- Copy one file to another
- Close a file
Correct Answer: 2. Write to a file
Explanation: The ‘fwrite’ function in C is used to write data to a file.
Quiz 216:
Which function is used to convert a character to its ASCII value in C?
- charToAscii()
- asciify()
- char()
- int()
Correct Answer: 4. int()
Explanation: To convert a character to its ASCII value in C, you can use an explicit type cast like int(character).
Quiz 217:
What is the purpose of the ‘strcat’ function in C?
- Compare two strings
- Copy one string to another
- Concatenate two strings
- Find the length of a string
Correct Answer: 3. Concatenate two strings
Explanation: The ‘strcat’ function in C is used to concatenate (append) two strings.
Quiz 218:
Which of the following is the correct syntax for declaring a structure in C?
- struct MyStruct { /* members */ };
- structure MyStruct { /* members */ };
- type MyStruct { /* members */ };
- new struct MyStruct { /* members */ };
Correct Answer: 1. struct MyStruct { /* members */ };
Explanation: The correct syntax for declaring a structure in C is struct MyStruct { /* members */ };.
Quiz 219:
What does the ‘volatile’ keyword do when applied to a variable in C?
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
- Indicates that a variable may be changed at any time
Correct Answer: 4. Indicates that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 220:
Which operator is used for pointer dereferencing in C?
- *
- &
- ->
- %
Correct Answer: 1. *
Explanation: The * operator is used for pointer dereferencing in C.
Quiz 221:
What is the purpose of the ‘const’ keyword in C when applied to a pointer?
- Indicates a constant value
- Specifies that the pointer cannot be modified
- Declares a constant pointer
- Specifies that the pointed-to value is constant
Correct Answer: 4. Specifies that the pointed-to value is constant
Explanation: When ‘const’ is applied to a pointer in C, it indicates that the pointed-to value is constant and cannot be modified through that pointer.
Quiz 222:
Which function is used to allocate memory for an array dynamically in C?
- malloc()
- calloc()
- realloc()
- alloc()
Correct Answer: 2. calloc()
Explanation: The calloc() function in C is used to dynamically allocate memory for an array and initializes the allocated memory to zero.
Quiz 223:
What is the purpose of the ‘strlen’ function in C?
- Concatenate two strings
- Compare two strings
- Find the length of a string
- Copy one string to another
Correct Answer: 3. Find the length of a string
Explanation: The ‘strlen’ function in C is used to determine the length (number of characters) of a string.
Quiz 224:
Which operator is used for bitwise AND in C?
- &
- |
- ^
- <<
Correct Answer: 1. &
Explanation: The & operator is used for bitwise AND in C.
Quiz 225:
What is the purpose of the ‘return’ statement in a function in C?
- Exit the program
- Return a value from the function
- Declare a variable
- Print a message
Correct Answer: 2. Return a value from the function
Explanation: The ‘return’ statement in C is used to send a value back from a function.
Quiz 226:
Which function is used to close a file in C?
- fclose()
- close()
- fileclose()
- shutfile()
Correct Answer: 1. fclose()
Explanation: The fclose() function is used to close a file in C after performing file operations.
Quiz 227:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 228:
What is the purpose of the ‘typedef’ keyword in C?
- Declare a new type name
- Define a constant value
- Specify the return type of a function
- Create an alias for a variable
Correct Answer: 1. Declare a new type name
Explanation: The ‘typedef’ keyword in C is used to create a new type name for an existing data type.
Quiz 229:
Which of the following is the correct syntax for declaring a function in C?
- def myFunction(): pass
- int myFunction() { /* code */ }
- void myFunction() { /* code */ }
- int myFunction(parameters) { /* code */ }
Correct Answer: 4. int myFunction(parameters) { /* code */ }
Explanation: The correct syntax for a function declaration in C includes the return type, function name, parameters, and the function body.
Quiz 230:
What is the purpose of the ‘union’ keyword in C?
- Declare a new type name
- Represent a collection of variables
- Create an empty function
- Allocate memory dynamically
Correct Answer: 2. Represent a collection of variables
Explanation: The ‘union’ keyword in C is used to represent a collection of variables that share the same memory location.
Quiz 231:
Which header file should be included to use the ‘scanf’ function in C?
- input.h
- output.h
- stdio.h
- stdlib.h
Correct Answer: 3. stdio.h
Explanation: The ‘scanf’ function is part of the Standard Input/Output library in C, and the header file stdio.h should be included.
Quiz 232:
What is the purpose of the ‘for’ loop in C?
- Execute a block of code at least once
- Iterate over a range of values
- Make decisions based on a condition
- Skip the current iteration and move to the next
Correct Answer: 2. Iterate over a range of values
Explanation: The ‘for’ loop in C is used to iterate over a range of values with a specified control structure.
Quiz 233:
Which operator is used for the modulo operation in C?
- %
- &
- |
- ^
Correct Answer: 1. %
Explanation: The % operator is used for the modulo operation in C, which returns the remainder of a division.
Quiz 234:
What does the ‘sizeof’ operator return when used with a pointer in C?
- Size of the pointer variable
- Size of the data type to which the pointer points
- Total size of the memory allocated for the pointer
- Size of the memory address held by the pointer
Correct Answer: 1. Size of the pointer variable
Explanation: When used with a pointer, the ‘sizeof’ operator in C returns the size of the pointer variable.
Quiz 235:
Which function is used to open a file in C for writing?
- fopen(“filename”, “r”)
- fopen(“filename”, “w”)
- fopen(“filename”, “a”)
- fopen(“filename”, “rb”)
Correct Answer: 2. fopen(“filename”, “w”)
Explanation: The fopen function with mode “w” is used to open a file in C for writing.
Quiz 236:
In C, what is the purpose of the ‘else’ statement?
- Declare a variable
- Specify an alternative block of code
- Loop through an array
- Terminate the program
Correct Answer: 2. Specify an alternative block of code
Explanation: The ‘else’ statement in C is used to specify an alternative block of code to be executed when the ‘if’ condition is false.
Quiz 237:
Which data type is used to store whole numbers in C?
- int
- float
- char
- double
Correct Answer: 1. int
Explanation: The int data type is used to store whole numbers in C.
Quiz 238:
What is the purpose of the ‘free’ function in C?
- Allocate memory dynamically
- Initialize memory to zero
- Deallocate memory
- Allocate memory for an array of elements
Correct Answer: 3. Deallocate memory
Explanation: The ‘free’ function in C is used to deallocate memory that was previously allocated dynamically using functions like ‘malloc’ or ‘calloc’.
Quiz 239:
Which header file should be included to use the ‘strlen’ function in C?
- string.h
- stdio.h
- stdlib.h
- math.h
Correct Answer: 1. string.h
Explanation: The ‘strlen’ function is part of the string manipulation functions in C, and the header file string.h should be included.
Quiz 240:
What is the purpose of the ‘goto’ statement in C?
- Exit the program
- Jump to a specified label within the program
- Make decisions based on a condition
- Loop through an array
Correct Answer: 2. Jump to a specified label within the program
Explanation: The ‘goto’ statement in C is used to transfer control to a specified label within the program.
Quiz 241:
Which operator is used for bitwise left shift in C?
- <<
- >>
- &
- |
Correct Answer: 1. <<
Explanation: The << operator is used for bitwise left shift in C, which shifts the bits to the left.
Quiz 242:
What is the role of the ‘include’ directive in C?
- Define a new function
- Include external files in the program
- Declare a variable
- Print a message
Correct Answer: 2. Include external files in the program
Explanation: The ‘include’ directive in C is used to include external files in the program, often header files containing declarations.
Quiz 243:
Which of the following is the correct syntax for a function declaration in C?
- function MyFunction() { /* code */ }
- def MyFunction(): pass
- void MyFunction() { /* code */ }
- int MyFunction(int param);
Correct Answer: 4. int MyFunction(int param);
Explanation: The correct syntax for a function declaration in C includes the return type, function name, and parameter list.
Quiz 244:
What is the purpose of the ‘switch’ statement in C?
- Loop through a range of values
- Make decisions based on multiple conditions
- Create an infinite loop
- Define a constant value
Correct Answer: 2. Make decisions based on multiple conditions
Explanation: The ‘switch’ statement in C is used to make decisions based on the values of an expression.
Quiz 245:
Which of the following is the correct way to declare a pointer in C?
- int ptr;
- pointer int;
- int *ptr;
- ptr int;
Correct Answer: 3. int *ptr;
Explanation: The correct way to declare a pointer in C is by placing the asterisk (*) before the variable name.
Quiz 246:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 247:
Which function is used to convert a string to an integer in C?
- atoi()
- itoa()
- strtoi()
- intToStr()
Correct Answer: 1. atoi()
Explanation: The atoi() function in C is used to convert a string to an integer.
Quiz 248:
What is the purpose of the ‘const’ keyword in a function declaration in C?
- Specify the return type
- Declare a constant variable
- Define a constant value
- Indicate a variable parameter
Correct Answer: 4. Indicate a variable parameter
Explanation: The ‘const’ keyword in a function declaration is used to indicate that a parameter is a constant.
Quiz 249:
Which of the following is a valid way to initialize an array in C?
- int myArray = {1, 2, 3};
- int myArray[] = {1, 2, 3};
- myArray = {1, 2, 3};
- int myArray[3] = {1, 2, 3};
Correct Answer: 2. int myArray[] = {1, 2, 3};
Explanation: The correct syntax for initializing an array in C is to use curly braces {} with the values enclosed.
Quiz 250:
What is the purpose of the ‘volatile’ keyword in C?
- Declare a constant value
- Specify the return type of a function
- Indicate that a variable may be changed at any time
- Create a dynamic variable
Correct Answer: 3. Indicate that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 251:
Which function is used to write a character to the standard output in C?
- putchar()
- writechar()
- printchar()
- displaychar()
Correct Answer: 1. putchar()
Explanation: The putchar() function in C is used to write a character to the standard output (usually the console).
Quiz 252:
What is the purpose of the ‘rand()’ function in C?
- Allocate memory dynamically
- Generate a random number
- Return the square root of a number
- Convert a string to uppercase
Correct Answer: 2. Generate a random number
Explanation: The ‘rand()’ function in C is used to generate a pseudo-random integer.
Quiz 253:
In C, how can you declare a constant variable?
- const var = 5;
- constant int var = 5;
- var const = 5;
- int const var = 5;
Correct Answer: 4. int const var = 5;
Explanation: To declare a constant variable in C, use the ‘const’ keyword before the data type.
Quiz 254:
Which operator is used for pointer arithmetic in C?
- +
- –
- *
- /
Correct Answer: 2. –
Explanation: The – operator is used for pointer arithmetic in C to find the difference between two pointers.
Quiz 255:
What is the purpose of the ‘do-while’ loop in C?
- Iterate over a range of values
- Make decisions based on a condition
- Execute a block of code at least once
- Create an infinite loop
Correct Answer: 3. Execute a block of code at least once
Explanation: The ‘do-while’ loop in C ensures that the code block is executed at least once, even if the condition is false.
Quiz 256:
Which header file should be included to use the ‘abs’ function in C for absolute value?
- stdlib.h
- math.h
- stdio.h
- limits.h
Correct Answer: 1. stdlib.h
Explanation: The ‘abs’ function for absolute value is part of the stdlib.h (standard library) in C.
Quiz 257:
What does the ‘static’ keyword do when applied to a variable in C?
- Allocates memory dynamically
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
Correct Answer: 3. Extends the variable’s scope to the entire program
Explanation: The ‘static’ keyword, when applied to a variable in C, extends its scope to the entire program.
Quiz 258:
Which of the following is a valid way to open a file in C for reading and writing?
- fopen(“file.txt”, “r”)
- fopen(“file.txt”, “w”)
- fopen(“file.txt”, “rw”)
- fopen(“file.txt”, “a+”)
Correct Answer: 4. fopen(“file.txt”, “a+”)
Explanation: The mode “a+” in fopen is used to open a file in C for reading and writing, with the file positioned at the end initially.
Quiz 259:
What is the purpose of the ‘continue’ statement in a loop in C?
- Skip the current iteration and move to the next
- Exit the loop
- Terminate the program
- Restart the loop from the beginning
Correct Answer: 1. Skip the current iteration and move to the next
Explanation: The ‘continue’ statement in C is used to skip the rest of the code inside a loop for the current iteration and move to the next one.
Quiz 260:
Which data type is used to store decimal numbers with single precision in C?
- float
- double
- long double
- decimal
Correct Answer: 1. float
Explanation: The float data type in C is used to store decimal numbers with single precision.
Quiz 261:
Which header file should be included to use the ‘pow’ function in C for exponentiation?
- math.h
- stdio.h
- stdlib.h
- power.h
Correct Answer: 1. math.h
Explanation: The ‘pow’ function for exponentiation is part of the math.h (mathematics) library in C.
Quiz 262:
What is the purpose of the ‘getchar’ function in C?
- Read a character from the standard input
- Print a character to the standard output
- Return a character from a function
- Initialize a character variable
Correct Answer: 1. Read a character from the standard input
Explanation: The getchar function in C is used to read a single character from the standard input (usually the keyboard).
Quiz 263:
In C, what is the purpose of the ‘sizeof’ operator when used with a data type?
- Return the size of a variable
- Return the size of a constant
- Return the size of a pointer
- Return the size of the specified data type
Correct Answer: 4. Return the size of the specified data type
Explanation: The ‘sizeof’ operator in C, when used with a data type, returns the size, in bytes, of the specified data type.
Quiz 264:
Which operator is used for logical OR in C?
- &&
- ||
- !
- |
Correct Answer: 2. ||
Explanation: The || operator is used for logical OR in C.
Quiz 265:
What is the purpose of the ‘fwrite’ function in C?
- Read from a file
- Write to a file
- Copy one file to another
- Close a file
Correct Answer: 2. Write to a file
Explanation: The ‘fwrite’ function in C is used to write data to a file.
Quiz 266:
Which function is used to convert a character to its ASCII value in C?
- charToAscii()
- asciify()
- char()
- int()
Correct Answer: 4. int()
Explanation: To convert a character to its ASCII value in C, you can use an explicit type cast like int(character).
Quiz 267:
What is the purpose of the ‘strcat’ function in C?
- Compare two strings
- Copy one string to another
- Concatenate two strings
- Find the length of a string
Correct Answer: 3. Concatenate two strings
Explanation: The ‘strcat’ function in C is used to concatenate (append) two strings.
Quiz 268:
Which of the following is the correct syntax for declaring a structure in C?
- struct MyStruct { /* members */ };
- structure MyStruct { /* members */ };
- type MyStruct { /* members */ };
- new struct MyStruct { /* members */ };
Correct Answer: 1. struct MyStruct { /* members */ };
Explanation: The correct syntax for declaring a structure in C is struct MyStruct { /* members */ };.
Quiz 269:
What does the ‘volatile’ keyword do when applied to a variable in C?
- Declares a constant value
- Extends the variable’s scope to the entire program
- Specifies that the variable is not modifiable
- Indicates that a variable may be changed at any time
Correct Answer: 4. Indicates that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.
Quiz 270:
Which operator is used for pointer dereferencing in C?
- *
- &
- ->
- %
Correct Answer: 1. *
Explanation: The * operator is used for pointer dereferencing in C.
Quiz 271:
What is the purpose of the ‘const’ keyword in C when applied to a pointer?
- Indicates a constant value
- Specifies that the pointer cannot be modified
- Declares a constant pointer
- Specifies that the pointed-to value is constant
Correct Answer: 4. Specifies that the pointed-to value is constant
Explanation: When ‘const’ is applied to a pointer in C, it indicates that the pointed-to value is constant and cannot be modified through that pointer.
Quiz 272:
Which function is used to allocate memory for an array dynamically in C?
- malloc()
- calloc()
- realloc()
- alloc()
Correct Answer: 2. calloc()
Explanation: The calloc() function in C is used to dynamically allocate memory for an array and initializes the allocated memory to zero.
Quiz 273:
What is the purpose of the ‘strlen’ function in C?
- Concatenate two strings
- Compare two strings
- Find the length of a string
- Copy one string to another
Correct Answer: 3. Find the length of a string
Explanation: The ‘strlen’ function in C is used to determine the length (number of characters) of a string.
Quiz 274:
Which operator is used for bitwise AND in C?
- &
- |
- ^
- <<
Correct Answer: 1. &
Explanation: The & operator is used for bitwise AND in C.
Quiz 275:
What is the purpose of the ‘return’ statement in a function in C?
- Exit the program
- Return a value from the function
- Declare a variable
- Print a message
Correct Answer: 2. Return a value from the function
Explanation: The ‘return’ statement in C is used to send a value back from a function.
Quiz 276:
Which function is used to close a file in C?
- fclose()
- close()
- fileclose()
- shutfile()
Correct Answer: 1. fclose()
Explanation: The fclose() function is used to close a file in C after performing file operations.
Quiz 277:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 278:
What is the purpose of the ‘typedef’ keyword in C?
- Declare a new type name
- Define a constant value
- Specify the return type of a function
- Create an alias for a variable
Correct Answer: 1. Declare a new type name
Explanation: The ‘typedef’ keyword in C is used to create a new type name for an existing data type.
Quiz 279:
Which of the following is the correct syntax for declaring a function in C?
- def myFunction(): pass
- int myFunction() { /* code */ }
- void myFunction() { /* code */ }
- int myFunction(parameters) { /* code */ }
Correct Answer: 4. int myFunction(parameters) { /* code */ }
Explanation: The correct syntax for a function declaration in C includes the return type, function name, parameters, and the function body.
Quiz 280:
What is the purpose of the ‘union’ keyword in C?
- Declare a new type name
- Represent a collection of variables
- Create an empty function
- Allocate memory dynamically
Correct Answer: 2. Represent a collection of variables
Explanation: The ‘union’ keyword in C is used to represent a collection of variables that share the same memory location.
Quiz 281:
Which header file should be included to use the ‘scanf’ function in C?
- input.h
- output.h
- stdio.h
- stdlib.h
Correct Answer: 3. stdio.h
Explanation: The ‘scanf’ function is part of the Standard Input/Output library in C, and the header file stdio.h should be included.
Quiz 282:
What is the purpose of the ‘for’ loop in C?
- Execute a block of code at least once
- Iterate over a range of values
- Make decisions based on a condition
- Skip the current iteration and move to the next
Correct Answer: 2. Iterate over a range of values
Explanation: The ‘for’ loop in C is used to iterate over a range of values with a specified control structure.
Quiz 283:
Which operator is used for the modulo operation in C?
- %
- &
- |
- ^
Correct Answer: 1. %
Explanation: The % operator is used for the modulo operation in C, which returns the remainder of a division.
Quiz 284:
What does the ‘sizeof’ operator return when used with a pointer in C?
- Size of the pointer variable
- Size of the data type to which the pointer points
- Total size of the memory allocated for the pointer
- Size of the memory address held by the pointer
Correct Answer: 1. Size of the pointer variable
Explanation: When used with a pointer, the ‘sizeof’ operator in C returns the size of the pointer variable.
Quiz 285:
Which function is used to open a file in C for writing?
- fopen(“filename”, “r”)
- fopen(“filename”, “w”)
- fopen(“filename”, “a”)
- fopen(“filename”, “rb”)
Correct Answer: 2. fopen(“filename”, “w”)
Explanation: The fopen function with mode “w” is used to open a file in C for writing.
Quiz 286:
In C, what is the purpose of the ‘else’ statement?
- Declare a variable
- Specify an alternative block of code
- Loop through an array
- Terminate the program
Correct Answer: 2. Specify an alternative block of code
Explanation: The ‘else’ statement in C is used to specify an alternative block of code to be executed when the ‘if’ condition is false.
Quiz 287:
Which data type is used to store whole numbers in C?
- int
- float
- char
- double
Correct Answer: 1. int
Explanation: The int data type is used to store whole numbers in C.
Quiz 288:
What is the purpose of the ‘free’ function in C?
- Allocate memory dynamically
- Initialize memory to zero
- Deallocate memory
- Allocate memory for an array of elements
Correct Answer: 3. Deallocate memory
Explanation: The ‘free’ function in C is used to deallocate memory that was previously allocated dynamically using functions like ‘malloc’ or ‘calloc’.
Quiz 289:
Which header file should be included to use the ‘strlen’ function in C?
- string.h
- stdio.h
- stdlib.h
- math.h
Correct Answer: 1. string.h
Explanation: The ‘strlen’ function is part of the string manipulation functions in C, and the header file string.h should be included.
Quiz 290:
What is the purpose of the ‘goto’ statement in C?
- Exit the program
- Jump to a specified label within the program
- Make decisions based on a condition
- Loop through an array
Correct Answer: 2. Jump to a specified label within the program
Explanation: The ‘goto’ statement in C is used to transfer control to a specified label within the program.
Quiz 291:
Which operator is used for bitwise left shift in C?
- <<
- >>
- &
- |
Correct Answer: 1. <<
Explanation: The << operator is used for bitwise left shift in C, which shifts the bits to the left.
Quiz 292:
What is the role of the ‘include’ directive in C?
- Define a new function
- Include external files in the program
- Declare a variable
- Print a message
Correct Answer: 2. Include external files in the program
Explanation: The ‘include’ directive in C is used to include external files in the program, often header files containing declarations.
Quiz 293:
Which of the following is the correct syntax for a function declaration in C?
- function MyFunction() { /* code */ }
- def MyFunction(): pass
- void MyFunction() { /* code */ }
- int MyFunction(int param);
Correct Answer: 4. int MyFunction(int param);
Explanation: The correct syntax for a function declaration in C includes the return type, function name, and parameter list.
Quiz 294:
What is the purpose of the ‘switch’ statement in C?
- Loop through a range of values
- Make decisions based on multiple conditions
- Create an infinite loop
- Define a constant value
Correct Answer: 2. Make decisions based on multiple conditions
Explanation: The ‘switch’ statement in C is used to make decisions based on the values of an expression.
Quiz 295:
Which of the following is the correct way to declare a pointer in C?
- int ptr;
- pointer int;
- int *ptr;
- ptr int;
Correct Answer: 3. int *ptr;
Explanation: The correct way to declare a pointer in C is by placing the asterisk (*) before the variable name.
Quiz 296:
In C, what is the purpose of the ‘break’ statement in a loop?
- Exit the program
- Exit the loop
- Skip the current iteration and move to the next
- Restart the loop from the beginning
Correct Answer: 2. Exit the loop
Explanation: The ‘break’ statement is used to exit a loop prematurely.
Quiz 297:
Which function is used to convert a string to an integer in C?
- atoi()
- itoa()
- strtoi()
- intToStr()
Correct Answer: 1. atoi()
Explanation: The atoi() function in C is used to convert a string to an integer.
Quiz 298:
What is the purpose of the ‘const’ keyword in a function declaration in C?
- Specify the return type
- Declare a constant variable
- Define a constant value
- Indicate a variable parameter
Correct Answer: 4. Indicate a variable parameter
Explanation: The ‘const’ keyword in a function declaration is used to indicate that a parameter is a constant.
Quiz 299:
Which of the following is a valid way to initialize an array in C?
- int myArray = {1, 2, 3};
- int myArray[] = {1, 2, 3};
- myArray = {1, 2, 3};
- int myArray[3] = {1, 2, 3};
Correct Answer: 2. int myArray[] = {1, 2, 3};
Explanation: The correct syntax for initializing an array in C is to use curly braces {} with the values enclosed.
Quiz 300:
What is the purpose of the ‘volatile’ keyword in C?
- Declare a constant value
- Specify the return type of a function
- Indicate that a variable may be changed at any time
- Create a dynamic variable
Correct Answer: 3. Indicate that a variable may be changed at any time
Explanation: The ‘volatile’ keyword in C is used to indicate that a variable’s value may be changed at any time by external forces.