C Programming – Basics of Functions

C Programming - Basics of Functions


Question 1
What is the output of this C code?
 #include 
 int main()
 {
 void foo();
 printf("1 ");
 foo();
 }
 void foo()
 {
 printf("2 ");
 }
A
1 2
B
Compile time error
C
1 2 1 2
D
Depends on the compiler
Question 2
What is the output of this C code?
#include 
int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}
A
Compile time error as foo is local to main
B
1 2
C
2 1
D
Compile time error due to declaration of functions inside main
Question 3
What is the output of this C code?
 #include 
 int main()
 {
 void foo();
 void f()
 {
 foo();
 }
 f();
 }
 void foo()
 {
 printf("2 ");
 }
A
2 2
B
2
C
Compile time error
D
Depends on the compiler
Question 4
What is the output of this C code?
#include 
void foo();
int main()
{
void foo();
foo();
return 0;
}
void foo()
{
printf("2 ");
}
A
Compile time error
B
2
C
Depends on the compiler
D
Depends on the standard
Question 5
What is the output of this C code?
#include 
void foo();
int main()
{
void foo(int);
foo(1);
return 0;
}
void foo(int i)
{
printf("2 ");
}
A
2
B
Compile time error
C
Depends on the compiler
D
Depends on the standard
Question 6
What is the output of this C code?
 #include 
 void foo();
 int main()
 {
 void foo(int);
 foo();
 return 0;
 }
 void foo()
 {
 printf("2 ");
 }
A
2
B
Compile time error
C
Depends on the compiler
D
Depends on the standard
Question 7
What is the output of this C code?
  include 
  void m()
  {
  printf("hi");
  }
  void main()
  {
  m();
  }
A
hi
B
Run time error
C
Nothing
D
Varies
Question 8
What is the output of this C code?
  include 
  void m()
  {
  printf("hi");
  }
  void main()
  {
  m();
  }
A
hi
B
Run time error
C
Nothing
D
Varies
Question 9
What is the output of this C code?
#include 
void m();
void n()
{
m();
}
void main()
{
void m()
{
printf("hi");
}
}
A
hi
B
Compile time error
C
Nothing
D
Varies
Question 10
What is the output of this C code?
#include 
void main()
{
m();
void m()
{
printf("hi");
}
}
A
hi
B
Compile time error
C
Nothing
D
Varies
Question 11
What is the output of this C code?
#include 
void main()
{
m();
}
void m()
{
printf("hi");
m();
}
A
Compile time error
B
hi
C
Infinite hi
D
Nothing
Question 12
What is the output of this C code?
#include 
void main()
{
static int x = 3;
x++;
if (x <= 5)
{
printf("hi");
main();
}
}
A
Run time error
B
hi
C
Infinite hi
D
hi hi
Question 13
Which of the following is a correct format for declaration of function?
A
return-type function-name(argument type);
B
return-type function-name(argument type) {}
C
return-type (argument type)function-name;
D
Both (a) and (b)
Question 14
 Which of the following function declaration is illegal?
A
int 1bhk(int);
B
int 1bhk(int a);
C
int 2bhk(int*, int []);
D
All of the mentioned
Question 15
Which function definition will run correctly?
A
int sum(int a, int b) return (a + b);
B
int sum(int a, int b) {return (a + b);}
C
int sum(a, b) return (a + b);
D
Both (a) and (b)
Question 16
Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ]
A
Yes, and we can use the function value conveniently
B
Yes, but we call the function again to get the value, not as convenient as in using variable
C
No, C does not support it.
D
This case is compiler dependent
Question 17
 The value obtained in the function is given back to main by using ________ keyword?
A
return
B
static
C
new
D
volatile 


Check Your Answers:

  1.  A
  2. B
  3. D
  4. B
  5. A
  6. B
  7. A
  8. A
  9. B
10. B
11. C
12. D
13. A
14. D
15. B
16. C
17. A
 

SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment