Fundamentals of Programming MCQs (Part-6)

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;

How do you access an element of an array in C?

A arr[3]
B arr->3
C arr{3}
D arr(3)

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 Python, how do you concatenate two strings?

A string1 + string2
B string1.add(string2)
C concat(string1, string2)
D string1.append(string2)

Which of these is used to declare a reference in C++?

A ref
B *
C &
D ptr

How do you read data from a file in Python?

A f.read()
B read(file)
C file.get()
D f.input()

In C, what does the * symbol represent in relation to pointers?

A Pointer declaration
B Memory allocation
C Dereferencing a pointer
D Pointer comparison

What is the purpose of the malloc() function in C?

A Initialize variables
B Deallocate memory
C Open file
D Allocate memory

In Java, which of these methods is used to read data from a file?

A read()
B open()
C next()
D readLine()

In C, how do you pass an array to a function?

A function(arr)
B function(&arr)
C function(arr[])
D function(*arr)

How do you find the length of a string in C?

A size()
B strlength()
C length()
D strlen()

How do you handle file exceptions in Python?

A try-except
B try-catch
C try-finally
D exception-throw

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 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 Python, how do you write to a file?

A write(file)
B file.write()
C file.output()
D write_output()