Beruflich Dokumente
Kultur Dokumente
Answer: (A)
Explanation: In C language, float, double and long double are called real data types. For “float”, “double”
and “long double”, the right format specifiers are %f, %lf and %Lf from the above options. It should be
noted that C standard has specified other format specifiers as well for real types which are %g, %e etc.
Answer: (B)
4. What is the return type of the function with prototype: "int func(char x, float v, double t);"
A. char
B. int
C. float
D. double
Answer: (B)
5. Which of the following is a valid function call (assuming the function exists)?
A. funct;
B. funct x, y;
C. funct();
D. int funct();
Answer: (C)
Answer: (C)
7. Which of the following reads in a string named x with one hundred characters?
A. cin.getline(x, 100, '\n');
B. cin.getline(100, x, '\n');
C. readline(x, 100, '\n');
D. read(x);
Answer: (A)
Answer: (C)
(A) 7 6 5
(B) 5 6 7
(C) 7 7 7
(D) Compiler Dependent
Answer: (D)
When parameters are passed to a function, the value of every parameter is evaluated before being
passed to the function.
Answer: (A)
In C, function parameters are always passed by value. Pass-by-reference is simulated in C by explicitly
passing pointer values.
Answer: (B)
In C, functions can return any type except arrays and functions. We can get around this limitation by
returning pointer to array or pointer to function.
Answer: (A)
Explanation: Name of the function is actually a pointer variable to the function and prints the
address of the function. Symbol table is implemented like this.
struct
{
char *name;
int (*funcptr)();
}
symtab[] = {
"func", func,
"anotherfunc", anotherfunc,
};
(A) n1 = 10, n2 = 9
(B) n1 = 10, n2 = 10
(C) n1 = 9, n2 = 9
(D) n1 = 9, n2 = 10
Answer: (A)
The size of str1 is 10 and size of str2 9.
When an array is initialized with string in double quotes, compiler adds a ‘\0’ at the end.
(A) GATE2011
(B) E2011
(C) 2011
(D) 011
Answer: (C)
See comments for explanation.
int main()
{
dynamic(2, 4, 6, 8);
dynamic(3, 6, 9);
return 0;
}
(A) 2 3
(B) Compiler Error
(C) 4 3
(D) 3 2
Answer: (A)
In c three continuous dots is known as ellipsis which is variable number of arguments of function. The
values to parameters are assigned one by one. Now the question is how to access other arguments. See
this for details.
17. What is the meaning of using static before function declaration? For example following
function sum is made static
static int sum(int x, int y, int z)
{
return (x + y + z);
}
(A) Static means nothing, sum() is same without static keyword.
(B) Function need not to be declared before its use
(C) Access to static functions is restricted to the file where they are declared
(D) Static functions are made inline
Answer: (C)
In C, functions are global by default. Unlike global functions, access to static functions is restricted to the
file where they are declared. We can have file level encapsulation using static variables/functions in C
because when we make a global variable static, access to the variable becomes limited to the file in
which it is declared.
18. In below program, what would you put in place of “?” to print “Quiz”?
#include <stdio.h>
int main()
{
char arr[] = "GeeksQuiz";
printf("%s", ?);
return 0;
}
(A) arr
(B) (arr+5)
(C) (arr+4)
(D) Not possible
Answer: (B)
Since %s is used, the printf statement will print everything starting from arr+5 until it finds ‘\0’
#include <iostream>
using namespace std;
void mani()
void mani()
{
cout<<"hai";
}
int main()
{
mani();
return 0;
}
a) hai
b) haihai
c) compile time error
d) none of the mentioned
Answer: c
We have to use the semicolon to declare the function in line 3. This is called a function declaration and a
function declaration ends with a semicolon.
20. 7. What is the output of this program?
#include <iostream>
using namespace std;
void fun(int x, int y)
{
x = 20;
y = 10;
}
int main()
{
int x = 10;
fun(x, x);
cout << x;
return 0;
}
a) 10
b) 20
c) compile time error
d) none of the mentioned
Answer: a
In this program, we called by value so the value will not be changed, So the output is 10