What does "printf" stand for in C programming?
a. Print File
b. Print Function
c. Print Format
d. Print Formatter
Answer: b. Print Function
Which of the following is not a valid C data type?
a. int
b. float
c. bool
d. char
Answer: c. bool
What is the syntax for declaring a constant in C?
a. const int x = 10;
b. constant x = 10;
c. int constant x = 10;
d. int x = constant 10;
Answer: a. const int x = 10;
In C, which escape sequence is used to represent the backslash character ""?
a. \n
b. \t
c. \
d. "
Answer: c. \
What does the "scanf" function do in C?
a. Print formatted text
b. Read input from the user
c. Calculate mathematical expressions
d. Define a function
Answer: b. Read input from the user
Which header file is needed to use the "printf" and "scanf" functions in C?
a. <stdio.h>
b. <stdlib.h>
c. <math.h>
d. <string.h>
Answer: a. <stdio.h>
What is the correct way to declare an array in C to store 10 integers?
a. int arr[10];
b. int arr[0:9];
c. int arr[1,10];
d. int arr(10);
Answer: a. int arr[10];
In C, what is the purpose of the "sizeof" operator?
a. To find the size of a function
b. To calculate the sum of numbers
c. To determine the size (in bytes) of a data type or variable
d. To print the size of an array
Answer: c. To determine the size (in bytes) of a data type or variable
Which operator is used for the logical OR operation in C?
a. &&
b. ||
c. !
d. &
Answer: b. ||
What is the output of the following C code?
int x = 5;
printf("%d", x++);
a. 5
b. 6
c. 7
d. Error
Answer: a. 5
Which keyword is used to exit a loop prematurely in C?
a. continue
b. exit
c. break
d. return
Answer: c. break
What is the purpose of the "strcmp" function in C?
a. To compare two strings
b. To concatenate two strings
c. To convert a string to uppercase
d. To find the length of a string
Answer: a. To compare two strings
Which loop in C is used to execute a block of code at least once before checking the condition?
a. while
b. for
c. do-while
d. switch
Answer: c. do-while
What is the scope of a local variable in C?
a. It is accessible throughout the entire program.
b. It is accessible only within the function where it is declared.
c. It is accessible from any function in the same file.
d. It is accessible only in the main function.
Answer: b. It is accessible only within the function where it is declared.
What is the correct way to allocate memory for an integer in C using dynamic memory allocation?
a. int *x = malloc(sizeof(int));
b. int *x = new int;
c. int x = malloc(sizeof(int));
d. int x = new int;
Answer: a. int *x = malloc(sizeof(int));
What is the purpose of the "const" keyword in a C function parameter?
a. It indicates that the parameter is constant and cannot be modified.
b. It indicates that the parameter must always have a value of 0.
c. It specifies the return type of the function.
d. It is used for defining macros.
Answer: a. It indicates that the parameter is constant and cannot be modified.
In C, what is the value of "NULL" typically used to represent?
a. The absence of a value
b. The value 0
c. A pointer to a valid memory location
d. A negative number
Answer: a. The absence of a value
What is the correct way to define a structure in C?
a. struct myStruct = {int x, float y};
b. struct myStruct {int x; float y;};
c. struct myStruct (int x, float y);
d. myStruct {int x; float y;}
Answer: b. struct myStruct {int x; float y;};
Which function is used to open a file for writing in C?
a. open()
b. fopen()
c. read()
d. write()
Answer: b. fopen()
What does the "EOF" constant represent in C?
a. End of File
b. End of Function
c. End of Loop
d. End of Frame
Answer: a. End of File
Which operator is used for pointer dereferencing in C?
a. &
b. *
c. ->
d. ::
Answer: b. *
In C, what is the purpose of the "typedef" keyword?
a. To define a new data type
b. To declare a variable
c. To include a library
d. To assign a value to a variable
Answer: a. To define a new data type
What is the output of the following C code?
int x = 5;
int y = x++;
printf("%d %d", x, y);
a. 5 5
b. 6 6
c. 6 5
d. 5 6
Answer: c. 6 5
In C, which keyword is used to declare a function?
a. func
b. function
c. def
d. void
Answer: d. void
What is the purpose of a function prototype in C?
a. To define the function's implementation
b. To declare the function's parameters
c. To declare the function's return type and name
d. To call the function
Answer: c. To declare the function's return type and name
What is the return type of a function that does not return any value in C?
a. int
b. void
c. char
d. double
Answer: b. void
In C, which function is automatically called when a program starts execution?
a. main
b. start
c. begin
d. initialize
Answer: a. main
What is the scope of a local variable in C?
a. Global to the entire program
b. Limited to the block or function where it is declared
c. Accessible from any function
d. Constant throughout the program
Answer: b. Limited to the block or function where it is declared
Pointers:
What does a null pointer in C point to?
a. The beginning of an array
b. A valid memory address
c. Nothing or undefined memory location
d. The end of a string
Answer: c. Nothing or undefined memory location
Which C programming library function is used to allocate memory dynamically during program execution?
a) malloc()
b) free()
c) sizeof()
d) include()
Answer: a malloc()
What is the operator used to access the value pointed to by a pointer in C?
a. *
b. &
c. ->
d. %
Answer: a. *
What is the size of a pointer variable in C?
a. 1 byte
b. 2 bytes
c. 4 bytes
d. Depends on the architecture (e.g., 4 or 8 bytes)
Answer: d. Depends on the architecture (e.g., 4 or 8 bytes)
What is the purpose of dynamic memory allocation in C?
a. To create global variables
b. To allocate memory at compile-time
c. To allocate memory at runtime for data structures like arrays and structures
d. To deallocate memory
Answer: c. To allocate memory at runtime for data structures like arrays and structures
In C, what is the significance of the "const" keyword when used with a pointer variable?
a. It indicates that the pointer cannot be changed.
b. It indicates that the pointed-to data cannot be changed.
c. It indicates that the pointer and data cannot be changed.
d. It indicates that the pointer is uninitialized.
Answer: b. It indicates that the pointed-to data cannot be changed.
Data Files:
Which function is used to open a file in C for reading?
a. open_file()
b. read_file()
c. fopen()
d. create_file()
Answer: c. fopen()
What is the file mode used to open a file in C for both reading and writing, creating a new file if it doesn't exist?
a. "r"
b. "w"
c. "a"
d. "r+"
Answer: d. "r+"
In C, how do you close a file after reading or writing operations?
a. fclose(file);
b. close(file);
c. file.close();
d. endfile();
Answer: a. fclose(file);
What is the purpose of the "fprintf" function in C?
a. To read formatted data from a file
b. To write formatted data to a file
c. To close a file
d. To delete a file
Answer: b. To write formatted data to a file
Which function is used to read a character from a file in C?
a. fgetc()
b. getc()
c. read_char()
d. getchar()
Answer: a. fgetc()
Structures:
In C, what is a structure?
a. A function
b. A data type that can hold multiple variables of different types
c. A loop control statement
d. A file handling operation
Answer: b. A data type that can hold multiple variables of different types
In C programming, what is the purpose of the struct keyword?
a) Define a new data type
b) Declare a variable
c) Perform arithmetic operations
d) Implement loops
Answer: a) Define a new data type
How do you access a member of a structure in C?
a. Using the structure name only
b. Using the member name only
c. Using the structure name followed by a dot (.)
d. Using the structure name followed by an arrow (->)
Answer: c. Using the structure name followed by a dot (.)
What is the purpose of typedef in C when used with structures?
a. To create a new data type alias for the structure
b. To define the structure's members
c. To allocate memory for the structure
d. To create an instance of the structure
Answer: a. To create a new data type alias for the structure
What is the keyword used to define a structure in C?
a. class
b. struct
c. typedef
d. record
Answer: b. struct
Which of the following statements is true about C structures?
a. Structures cannot contain other structures.
b. Structures can only hold variables of the same data type.
c. Structures can have functions as members.
d. Structures are a form of dynamic data types.
Answer: c. Structures can have functions as members.
Which of the following is not a fundamental data type in C programming?
a) int
b) float
c) string
d) char
Answer: c) string
Comments
Post a Comment