Programming - Programming in C
MCQS
A. Print format
B. Print function
C. Print file
D. Print formatted output
No Explanation
A. int
B. char
C. real
D. double
'real' is not a valid data type in C.
A. Returns size of a variable
B. Returns ASCII value
C. Returns the memory address
D. Returns pointer size
'sizeof' returns the size in bytes of a variable.
A. // Comment
B. /* Comment */
C. # Comment
D. -- Comment
'//' is used for single-line comments in C.
A. 16
B. 11
C. 10
D. 13
Operator precedence: 3 * 2 = 6, 5 + 6 = 11.
A. const
B. constant
C. Const
D. #define
'const' is used to declare constants in C.
A. Exit the program
B. Skip to the next case
C. Exit the loop
D. Terminate the switch statement
'break' is used to terminate a switch statement.
A. function myFunction()
B. def myFunction():
C. void myFunction()
D. myFunction()
In C, function definition starts with the return type.
A. Allocate memory for an array
B. Free allocated memory
C. Allocate memory for a variable
D. Allocate and initialize memory for an array
'calloc' allocates and initializes memory for an array.
A. Create a new data type
B. Define a variable
C. Declare a function
D. Include a header file
'typedef' is used to create new data types in C.
A. %f
B. %d
C. %s
D. %c
%f is used for printing float values in C.
A. read()
B. getchar()
C. getc()
D. scanf()
'getchar()' is used to read a character from standard input.
A. A
B. B
C. 66
D. 67
'A' + 1 results in the ASCII value of 'B'.
A. int* ptr;
B. pointer ptr;
C. *ptr int;
D. ptr* int;
Syntax for declaring a pointer: type *variable_name;
A. Exit the loop
B. Skip to the next iteration
C. Restart the loop
D. Terminate the program
'continue' skips the rest of the loop and moves to the next iteration.
A. #include "file.h"
B. include "file.h"
C. #include
D. include
'#include' is used to include a header file in C.
A. Define a constant
B. Declare a variable
C. Create a static function
D. Preserve variable value between function calls
'static' preserves the variable value between function calls.
A. Hello
B. ello
C. H
D. e
"Hello" + 1 points to the second character, resulting in "ello".
A. ->
B. *
C. ::
D. .
'*' is the dereference operator in C.
A. Read a character
B. Read a string
C. Read an integer
D. Read a float
'fgets' is used to read a string from a file or standard input.
A. Concatenate strings
B. Copy strings
C. Compare strings
D. Convert strings
'strcpy' is used to copy strings in C.
A. fopen("file.txt", "r");
B. open("file.txt", "w");
C. fopen("file.txt", "w");
D. open("file.txt", "r");
'fopen' with "w" opens a file for writing in C.
A. Concatenate strings
B. Copy strings
C. Compare strings
D. Convert strings
'strcat' is used to concatenate strings in C.
A. close(file);
B. fclose(file);
C. file.close();
D. endfile(file);
'fclose' is used to close a file in C.
A. Size of the pointer
B. Size of the data type pointed to
C. Size of the memory allocated
D. Size of the address
'sizeof' returns the size of the pointer variable.
A. &&
B.
D.
A. -6
B. 5
C. 6
D. -5
~5 results in the bitwise complement, which is -6.
A. Combine two arrays
B. Combine two structures
C. Combine two functions
D. Combine two variables
'union' is used to combine two or more structures in C.
A. $
B. #
C. @
D. &
Preprocessor directives start with '#'.
A. Allocate memory for an array
B. Free allocated memory
C. Allocate memory for a variable
D. Allocate and initialize memory for an array
'malloc' is used to allocate memory for an array.
A. strcmp()
B. strcompare()
C. compare()
D. stringcmp()
'strcmp()' is used to compare two strings in C.
A. A
B. B
C. 65
D. 66
65 corresponds to the ASCII value of 'A'.
A. const *ptr;
B. *const ptr;
C. const ptr;
D. const int *ptr;
'const' after '*' makes the pointer itself constant.
A. Execute the loop at least once
B. Iterate over a range of values
C. Execute the loop until a condition is true
D. Execute the loop based on a condition
'do-while' ensures that the loop is executed at least once.
A. Declare a volatile variable
B. Indicate an unstable function
C. Declare a constant variable
D. Indicate a variable that can change unexpectedly
'volatile' is used to indicate a variable that can change unexpectedly.
A. Generate a random float
B. Generate a random integer
C. Return a fixed value
D. Find the square root
'rand' generates a random integer in C.
A. global var;
B. int global;
C. extern int global;
D. static global;
'extern' is used to declare a global variable in C.
A. 3.33
B. 3.0
C. 3
D. 3.333333
Division of integers results in an integer, so 10 / 3 is 3.0.
A. Compare strings
B. Concatenate strings
C. Copy a specified number of characters from one string to another
D. Convert strings
'strncpy' is used to copy a specified number of characters from one string to another.
A. int arr[][];
B. int arr[];
C. int arr[][] = new int[];
D. int arr[][3];
'int arr[][3];' declares a two-dimensional array in C.
A. Search for a character in a string
B. Search for a string in another string
C. Compare strings
D. Concatenate strings
'strchr' is used to search for a character in a string.
A. const *ptr;
B. *const ptr;
C. const ptr;
D. const int *ptr;
'const' after '*' makes the pointed data constant.
A. Declare a structure
B. Declare an enumeration
C. Declare a function
D. Declare a variable
'enum' is used to declare an enumeration in C.
A. stdlib.h
B. string.h
C. stdio.h
D. math.h
'stdio.h' is required for file input and output operations in C.
A. Tokenize a string
B. Compare strings
C. Concatenate strings
D. Copy strings
'strtok' is used to tokenize a string in C.
A. struct myStruct;
B. struct = myStruct;
C. myStruct struct;
D. struct myStruct { };
'struct myStruct { };' declares a structure in C.
A. Close a file
B. Terminate the program
C. Return from a function
D. Print a message
'exit()' is used to terminate the program in C.
A. 4
B. 8
C. 2
D. 1
'sizeof(1.5)' returns the size of the double data type, which is typically 8 bytes.
A. int constant = 5;
B. constant int = 5;
C. const int constant = 5;
D. int constant(5);
'const' is used to declare a constant in C.
A. 20
B. 10
C. 40
D. 5
'<<' is the left shift operator, 5 << 2 results in 20.
A. #define MACRO_NAME()
B. define MACRO_NAME():
C. #macro MACRO_NAME
D. #define MACRO_NAME value
'#define MACRO_NAME value' defines a macro in C.
A. Get a character without echoing to the screen
B. Get a character with echoing to the screen
C. Get an integer
D. Get a float
'getch' gets a character without echoing it to the screen.
A. Declare an automatic variable
B. Declare an automatic pointer
C. Automatically allocate memory
D. Auto-cast variables
'auto' is used to declare automatic variables in C.
A. &
B.
C. ^
D
A. 1
B. 2
C. 0
D. 3
'%' is the modulo operator, 10 % 3 results in 1.
A. const *ptr;
B. *const ptr;
C. const ptr;
D. const int *const ptr;
'const int *const ptr;' defines a constant pointer to a constant integer in C.
A. Compare memory
B. Copy memory
C. Concatenate memory
D. Allocate memory
'memcpy' is used to copy memory in C.
A. int (*funcPtr)();
B. int funcPtr();
C. (*int funcPtr)();
D. int *funcPtr();
'int (*funcPtr)();' declares a function pointer in C.
A. 10
B. 20
C. 1
D. 0
The ternary operator evaluates to 10 when the condition is true.
A. Concatenate strings
B. Copy strings
C. Compare strings
D. Convert strings
'strcmp' is used to compare strings in C.
A. int arr[];
B. int arr[10];
C. int *arr = malloc(10 * sizeof(int));
D. int arr[10] = new int[10];
'malloc' is used to allocate memory for a dynamic array in C.
A. a
B. A
C. b
D. B
'a' - 32 results in the ASCII value of 'A'.
A. #define MACRO_NAME() { }
B. #define MACRO_NAME { }
C. #macro MACRO_NAME { }
D. #macro MACRO_NAME() { }
#define MACRO_NAME { } defines a multi-line macro in C.
A. Flush the keyboard buffer
B. Flush the output buffer
C. Flush the standard input
D. Flush the file stream
'fflush' is used to flush the output buffer in C.
A. int (*funcPtr[5])();
B. int funcPtr5;
C. (*int funcPtr[5])();
D. int *funcPtr5;
'int (*funcPtr[5])();' declares an array of function pointers in C.