Programming
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.
A. A scripting language
B. A markup language
C. A programming language
D. A database language
Java is a programming language.
A. constant
B. const
C. final
D. static
'final' is used to declare constants in Java.
A. main() method
B. start() method
C. execute() method
D. run() method
The 'main()' method is the entry point in Java.
A. int
B. float
C. double
D. class
'class' is not a primitive data type in Java.
A. Refer to the current object
B. Refer to the parent class
C. Refer to the child class
D. Refer to the global scope
'this' refers to the current object in Java.
A. new
B. malloc
C. instantiate
D. create
'new' is used for object instantiation in Java.
A. true
B. false
C. 0
D. 1
The default value of a boolean variable is 'false'.
A. Using interfaces
B. Using abstract classes
C. Using multiple extends keyword
D. Java doesn't support multiple inheritance
Multiple inheritance is achieved using interfaces in Java.
A. Invoke superclass constructor
B. Refer to the subclass object
C. Invoke a static method
D. Create a superclass instance
'super' is used to invoke the superclass constructor.
A. ArrayList
B. HashSet
C. HashMap
D. Vector
'Vector' is a synchronized collection class in Java.
A. Define exceptions
B. Throw exceptions
C. Catch exceptions
D. Propagate exceptions
'throws' is used to propagate exceptions in Java.
A. finalize()
B. dispose()
C. clean()
D. destroy()
'finalize()' is called during garbage collection.
A. Hello3
B. Hello12
C. Hello21
D. Compile error
Concatenation from left to right: "Hello" + 1 = "Hello1", then "Hello1" + 2 = "Hello21".
A. final
B. static
C. private
D. protected
'final' prevents method overriding in Java.
A. Check if an object is an instance of a class
B. Compare two objects
C. Check if a class is an instance of an object
D. Check if an object is null
'instanceof' is used to check if an object is an instance of a class.
A. Abstract class can have constructors
B. Interface can have constructors
C. Abstract class can have abstract methods
D. Interface can have non-abstract methods
Abstract classes can have constructors, while interfaces cannot.
A. Skip to the next iteration
B. Exit the loop
C. Restart the loop
D. Skip to the next loop
'break' is used to exit a loop in Java.
A. int[] arr;
B. int arr();
C. array arr;
D. array[] arr;
'int[] arr;' declares an array of integers in Java.
A. using
B. extends
C. implements
D. inheritance
'implements' is used to implement interfaces in Java.
A. 7
B. 8
C. 7.8
D. 8.0
'Math.floor(7.8)' returns the largest integer less than or equal to 7.8, which is 7.0.
A. Define exceptions
B. Throw exceptions
C. Catch and handle exceptions
D. Propagate exceptions
'try-catch' is used to catch and handle exceptions in Java.
A. Runnable
B. Serializable
C. Comparable
D. Cloneable
'Serializable' is a marker interface in Java.
A. Using the run() method
B. Extending the Thread class
C. Implementing the Runnable interface
D. Both B and C
Both extending Thread and implementing Runnable can create a thread in Java.
A. Define exceptions
B. Throw exceptions
C. Catch exceptions
D. Cleanup code
'finally' is used for cleanup code that always executes, whether an exception occurs or not.
A. Create a static method
B. Create a static variable
C. Define a constant
D. Create a static class
'static' is used to create static variables in Java.
A. compare()
B. equals()
C. compareTo()
D. equality()
'equals()' is used to compare objects for equality in Java.
A. 3.33
B. 3.0
C. 3
D. 3.333333
Division involving a double results in a double, so 10 / 3.0 is 3.333333.
A. Object obj = new Object();
B. class obj = new class();
C. Object obj = createObject();
D. obj = createObject();
'new' is used to create an object of a class in Java.
A. Execute the default case
B. Define a default value
C. Provide a default constructor
D. Specify default permissions
'default' is used for the default case in a switch statement.
A. true
B. false
C. Compile error
D. Runtime error
String literals with the same content are interned, so "Java" == "Java" is true.
A. read()
B. input()
C. System.in.read()
D. Scanner.next()
'Scanner.next()' is commonly used to read data from the keyboard in Java.
A. Garbage collection
B. Exception handling
C. Object cloning
D. Method overloading
'finalize' is called during garbage collection in Java.
A. const int CONSTANT = 5;
B. final int CONSTANT = 5;
C. static final int CONSTANT = 5;
D. public final int CONSTANT = 5;
'static final' is used to declare constants in an interface in Java.
A. ArrayList arr = new ArrayList();
B. List arr = new List();
C. List arr = new ArrayList();
D. ArrayList arr = new List();
'ArrayList arr = new ArrayList();' creates an ArrayList in Java.
A. Invoke the superclass constructor
B. Refer to the parent class
C. Invoke the subclass constructor
D. Create a superclass instance
'super()' is used to invoke the superclass constructor in Java.