In C, what is the correct syntax for declaring a pointer?
A pointer int p;
B int& p;
C ptr int p;
D int *p;
In C, pointers are declared using the syntax int *p;, where int is the type of data the pointer will point to, and *p indicates that p is a pointer to an integer.
How do you access an element of an array in C?
A arr[3]
B arr->3
C arr{3}
D arr(3)
In C, array elements are accessed using square brackets and an index. For example, arr[3] accesses the 4th element of the array (arrays are 0-indexed).
What is the purpose of the fopen() function in C?
A Read a file
B Close a file
C Open a file
D Write to a file
In C, the fopen() function is used to open a file. It allows you to specify the file name and the mode (e.g., read, write), and it returns a pointer to the file stream for further operations.
In Python, how do you concatenate two strings?
A string1 + string2
B string1.add(string2)
C concat(string1, string2)
D string1.append(string2)
In Python, string concatenation is done using the + operator. For example, “Hello” + ” ” + “World” results in the string “Hello World”. It combines both strings into one.
Which of these is used to declare a reference in C++?
A ref
B *
C &
D ptr
In C++, the & symbol is used to declare a reference. It binds a reference variable to an existing variable, allowing direct access to the original variable’s value.
How do you read data from a file in Python?
A f.read()
B read(file)
C file.get()
D f.input()
In Python, after opening a file using open(), you can read the file’s contents using the read() method. This method reads the entire content of the file into a string.
In C, what does the * symbol represent in relation to pointers?
A Pointer declaration
B Memory allocation
C Dereferencing a pointer
D Pointer comparison
In C, the * symbol is used to dereference a pointer, i.e., to access the value that the pointer is pointing to. For example, *ptr gives the value stored at the memory address contained in ptr.
What is the purpose of the malloc() function in C?
A Initialize variables
B Deallocate memory
C Open file
D Allocate memory
In C, the malloc() function is used to allocate dynamic memory. It reserves a block of memory of a specified size at runtime and returns a pointer to the beginning of the block.
In Java, which of these methods is used to read data from a file?
A read()
B open()
C next()
D readLine()
In Java, the read() method of the FileReader or BufferedReader class is used to read data from a file. It can read a single character or an array of characters from the file.
In C, how do you pass an array to a function?
A function(arr)
B function(&arr)
C function(arr[])
D function(*arr)
In C, arrays are passed to functions by reference. You declare the array in the function parameter as arr[] to pass the entire array. Changes made in the function affect the original array.
How do you find the length of a string in C?
A size()
B strlength()
C length()
D strlen()
In C, the strlen() function is used to determine the length of a string. It counts the number of characters in the string, excluding the null terminator ‘\0’.
How do you handle file exceptions in Python?
A try-except
B try-catch
C try-finally
D exception-throw
In Python, exceptions are handled using try-except blocks. The code that might raise an exception is placed inside the try block, and the except block handles the exception if it occurs.
In Java, how do you declare an array of integers with 5 elements?
A int arr[5];
B arr[] = {1, 2, 3, 4, 5};
C int arr[] = new int[5];
D int arr = [1, 2, 3, 4, 5];
In Java, arrays are declared using the new keyword. The statement int arr[] = new int[5]; declares an array of integers with 5 elements. The array will be initialized with default values.
In C++, how do you initialize a string object?
A string s = “Hello”;
B string s(“Hello”);
C string s; s = “Hello”;
D All of the above
In C++, a string can be initialized in several ways: string s = “Hello”;, string s(“Hello”);, or by declaring the string and assigning a value later. All are valid methods to initialize a string.
In Python, how do you write to a file?
A write(file)
B file.write()
C file.output()
D write_output()
In Python, after opening a file in write mode using open(), you can use the write() method to write data to the file. The method writes a string or a set of characters into the file.