C Functions
C Functions
int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}
B. 1 2
C. 2 1
int main()
{
void foo();
void f()
{
foo();
}
f();
}
void foo()
{
printf("2 ");
}
A. 2 2
B. 2
void foo();
int main()
{
void foo();
foo();
return 0;
}
void foo()
{
printf("2 ");
}
B. 2
A. 2
void foo();
int main()
{
void foo(int);
foo();
return 0;
}
void foo()
{
printf("2 ");
}
A. 2
void m()
printf("hi");
void main()
m();
A. hi
C. Nothing
D. Varies
void m();
void n()
{
m();
void main()
void m()
printf("hi");
A. hi
C. Nothing
D. Varies
void main()
m();
void m()
{
printf("hi");
A. hi
C. Nothing
D. Varies
void main()
m();
void m()
printf("hi");
m();
B. hi
C. Infinite hi
D. Nothing
void main()
static int x = 3;
x++;
if (x <= 5)
printf("hi");
main();
A. Runtime error
B. hi
C. infinite hi
D. hi hi
A. int 1bhk(int);
return (a + b);
{return (a + b);}
C. int sum(a, b)
return (a + b);
14. Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ]
B. Yes, but we call the function again to get the value, not as convenient as in using
variable
15. The value obtained in the function is given back to main by using ________ keyword?
A. return
B. static
C. new
D. volatile
A. int
B. float
C. double
A. double func();
int main(){}
double func(){}
B. double func(){};
int main(){}
C. int main()
double func();
double func(){//statements}
18. What is the output of this code having void return-type function?
void foo()
return 1;
}
void main()
{
int x = 0;
x = foo();
printf("%d", x);
}
A. 1
B. 0
Answer: Option D
Explanation:
None.
19. What will be the data type returned for the following function?
int func()
return (double)(char)5.0;
A. char
B. int
C. double
int func(int);
double func(int);
int func(float);
A. A function with same name cannot have different signatures
void main()
{
int k = m();
printf("%d", k);
}
void m()
{
printf("hello");
}
A. hello 5
B. Error
C. Nothing
D. Junk value
int *m()
int *p = 5;
return p;
void main()
int *k = m();
printf("%d", k);
A. 5
B. Junk value
C. 0
D. 5
int *m();
void main()
int *k = m();
printf("hello ");
printf("%d", k[0]);
int *m()
return a;
A. hello 5 8
B. hello 5
D. Compilation error
int *m();
void main()
int k = m();
printf("%d", k);
int *m()
{
return a;
A. 5
B. 8
C. Nothing
D. Varies
void m(int k)
printf("hi");
void m(double k)
printf("hello");
void main()
m(3);
}
A. hi
B. hello
D. Nothing
26. What is the default return type if it is not specified in function definition?
A. void
B. int
C. double
D. short int
int foo();
int main()
{
int i = foo();
}
foo()
{
printf("2 ");
return 2;
}
A. 2
B. Compile time error
A. 2
A. true
B. false
enum m foo();
int main()
enum m i = foo();
printf("%d\n", i);
int foo()
{
return JAN;
B. 0
void main()
m();
printf("%d", x);
int x;
void m()
{
x = 4;
}
A. 4
C. 0
D. Undefined
Answer & Explanation
Answer: Option B
Explanation:
None.
int x;
void main()
{
printf("%d", x);
}
A. Junk value
C. 0
D. Undefined
int x = 5;
void main()
int x = 3;
printf("%d", x);
{
x = 4;
printf("%d", x);
B. 3 3
C. 3 5
D. 3 4
int x = 5;
void main()
int x = 3;
printf("%d", x);
int x = 4;
printf("%d", x);
A. 3 3
B. 3 4
C. 3 5
A. Internal
B. External
A. Internal
B. External
A. a
B. b
C. c
D. d
A. 9
B. 10
C. 11
double var = 8;
int main()
int var = 5;
printf("%d", var);
A. 5
B. 8
double i;
int main()
printf("%g\n",i);
return 0;
}
A. 0
B. 0.000000
C. Garbage value
42. Which part of the program address space is p stored in the code given below?
int *p = NULL;
int main()
int i = 0;
p = &i;
return 0;
A. Code/text segment
B. Data segment
C. Bss segment
D. Stack
43. Which part of the program address space is p stored in the code given below?
int *p;
int main()
int i = 0;
p = &i;
return 0;
A. Code/text segment
B. Data segment
C. Bss segment
D. Stack
int i;
int main()
printf("%d\n", i);
A. 0
B. false
45. Property of external variable to be accessed by any source file is called by C90
standard as:
A. external linkage
B. external scope
C. global scope
D. global linkage
int *i;
int main()
if (i == NULL)
printf("true\n");
return 0;
A. true
D. Nothing
Answer & Explanation
Answer: Option A
Explanation:
None.
int *i;
int main()
if (i == 0)
printf("true\n");
return 0;
A. true
D. Nothing
static int x = 5;
void main()
x = 9;
{
int x = 4;
printf("%d", x);
A. 9
B. 4
C. 5
D. 0
void main()
m();
m();
void m()
static int x = 5;
x++;
printf("%d", x);
}
A. 6 7
B. 6 6
C. 5 5
D. 5 6
void main()
static int x;
A. 0
B. 1
C. Junk value
static int x;
void main()
{
int x;
A. 0
B. Junk value
D. Nothing
void main()
static double x;
int x;
A. 0
B. Nothing
D. Junk value
void main()
static int x;
if (x++ < 2)
main();
C. Varies
A. Variables
B. Functions
C. Structures
A. stack
B. queue
C. priority queue
D. random
Answer & Explanation
Answer: Option A
Explanation:
None.
A. enum
B. union
C. auto
D. volatile
Answer: Option C
Explanation:
None.
59. Default storage class if not any is specified for a local variable, is auto:
A. true
B. false
Answer: Option A
Explanation:
None.
60. Automatic variables are stored in:
A. stack
B. data segment
C. register
D. heap
Answer: Option A
Explanation:
None.
A. Internal linkage
B. External linkage
C. No linkage
Answer: Option C
Explanation:
None.
int main()
{
auto i = 10;
printf("%d\n", i);
A. 10
Answer: Option A
Explanation:
None.
Answer: Option A
Explanation:
None.
D. Only 1
Answer: Option C
Explanation:
None.
A. heap
B. Data segment
C. Code segment
D. stack
Answer: Option D
Explanation:
None.
66. What is the output of this C code?
void main()
{
int x;
}
here x is?
A. automatic variable
B. static variable
C. global variable
D. register variable
A. 0
B. Junk value
C. Nothing
68. Which of the following storage class supports char data type?
A. register
B. static
C. auto
D. All of the mentioned
Answer: Option D
Explanation:
None.
A. auto
B. extern
C. static
D. register
Answer: Option A
Explanation:
None.
int x;
void main()
{
printf("%d", x);
}
A. Junk value
C. 0
D. Undefined
Answer: Option C
Explanation:
None.
int x = 5;
void main()
{
int x = 3;
printf("%d", x);
{
x = 4;
}
printf("%d", x);
}
B. 3 3
C. 3 5
D. 3 4
Answer: Option D
Explanation:
None
B. From the point of declaration to the end of the file in which it is defined
D. From the point of declaration to the end of the file being compiled
Answer: Option D
Explanation:
None.
B. From the point of declaration to the end of the file in which it is defined
D. From the point of declaration to the end of the file being compiled
Answer: Option D
Explanation:
None.
int b;
int main()
{
int c;
return 0;
}
int a;
A. a
B. b
C. c
Answer: Option B
Explanation:
None.
75. Array sizes are optional during array declaration by using ______ keyword.
A. auto
B. static
C. extern
D. register
Answer: Option C
Explanation:
None.
A. 4
B. 3
C. 0
D. Undefined
Answer: Option A
Explanation:
None.
int x = 5;
void main()
{
int x = 3;
m();
printf("%d", x);
}
void m()
{
x = 8;
n();
}
void n()
{
printf("%d", x);
}
A. 8 3
B. 8 5
C. 3 8
D. 5 3
Answer: Option A
Explanation:
None.
void main()
{
m();
m();
}
void m()
{
static int x = 5;
x++;
printf("%d", x);
}
A. 6 7
B. 6 6
C. 5 5
D. 5 6
Answer: Option A
Explanation:
None.
static int x;
void main()
{
int x;
printf("x is %d", x);
}
A. 0
B. Junk value
D. Nothing
Answer: Option B
Explanation:
None.
void main()
{
static double x;
int x;
printf("x is %d", x);
}
A. Nothing
B. 0
D. Junk value
Answer: Option C
Explanation:
None.
void main()
{
static int x;
if (x++ < 2)
main();
}
C. Varies
Answer: Option D
Explanation:
None.
Answer: Option B
Explanation:
None.
83. Assignment statements assigning value to local static variables are executed only
once?
A. true
B. false
Answer: Option B
Explanation:
None.
A. %s
B. %d
C. %f
Answer: Option B
Explanation:
None.
A. true
B. false
Answer: Option B
Explanation:
None.
A. YES
B. NO
Answer: Option B
Explanation:
None.