C Function Aptitude Questions with Answer
1.What are storage classes in ‘C’ language? choose multiple
a) auto keyword b) static keyword c) register keyword d) extern keyword e) automatic f) static
a) auto keyword b) static keyword c) register keyword d) extern keyword e) automatic f) static
Ans: e,f
2. What are storage class specifiers in ‘C’ language?
Ans: 4(auto,register,static,extern)
3. How many variables scopes are there in ‘C’ language?
Ans: 4(body,function,program,file)
Ans: 4(body,function,program,file)
4. What is the output of the following code?
#include<stdio.h>
int main()
{
int i;
for(i=0;i<5;i++)
{
static int a=0;
int b=0;
a++;
b++;
printf(“na=%d”,a);
printf(“,b=%d”,b);
}
return 0;
}
Ans: a=1, b=1
a=2,b=1
a=3,b=1
a=4,b=1
a=5 ,b=1
5. What is the output of the following code?
#include <stdio.h>
int main()
{
static int s;
++s;
printf(“n%d”,s);
if(s<=3)
main();
printf(“n%d”,s);
return 0;
}
Ans: 1 2 3 4 4 4 4 4
6. What is the output of the following code?
#include<stdio.h>
extern int a; int main()
{
printf(“na=%d”,a);
return 0;
}
Ans: Linking Error undefined symbol _a
7. What is the output of the following code?
#include<stdio.h>
int a;
int main()
{
printf(“n a = %d”,a);
return 0;
}
Ans: a=0
8. What is the output of the following code?
#include<stdio.h>
extern int a;
int main()
{
printf(“n a = %d”,a);
return 0;
}
int a;
Ans: a=0
9. What is the output of the following code?
#include<stdio.h>
extern int a;
int main()
{
printf(“n a = %d”,a);
return 0;
}
int a=5;
Ans: a=5
10. What is the output of the following code?
#include<stdio.h>
extern int a=5;
int main()
{
void fun();
printf(“n a = %d”,a);
fun(); return 0;
}
int a;
void fun()
{
printf(“n in fun a = %d”,a);
}
Ans: a=5,a=5
11. What is the output of the following code?
#include<stdio.h>
extern int a;
int main()
{
void fun();
printf(“n a = %d”,a);
fun();
return 0;
}
int a=7;
void fun()
{
printf(“n in fun a = %d”,a);
}
Ans: a=7,a=7
12. What is the output of the following code?
#include<stdio.h>
extern int a=5;
int main()
{
void fun();
printf(“n a = %d”,a);
fun();
return 0;
}
int a;
void fun()
{
printf(“n in fun a = %d”,a);
}
Ans: a=5,a=5
13. What is the output of the following code?
#include<stdio.h>
void fun(int _)
{
printf(“%d”,_);
}
int main()
{
fun(23);
return 0;
}
Ans: 23
14. Identify the compiler error in the following code?
#include<stdio.h>
void fun(auto int _)
{
printf(“%d”,_);
}
int main()
{
fun(23);
return 0;
}
Ans: Error
15. Identify the compiler error in the following code?
#include<stdio.h>
void fun(static int _)
{
printf(“%d”,_);
}
int main()
{
fun(23);
return 0;
}
Ans: Error
16. Identify the compiler error in the following code?
#include<stdio.h>
void fun( extern int _)
{
printf(“%d”,_);
}
int main()
{
fun(23);
return 0;
}
Ans: Error
17. Identify the compiler error in the following code?
#include<stdio.h>
void fun(register int _)
{
printf(“%d”,_);
}
int main()
{
fun(23);
return 0;
}
Ans: 23
18. Identify the compiler error in the following code?
#include<stdio.h>
void fun(typedef int _)
{
printf(“%d”,_);
}
int main()
{
fun(23);
return 0;
}
Ans: Error
19. What is the output of the following code?
#include<stdio.h>
int main()
{
auto a;
register r;
static s;
extern e;
printf(“n%d”,sizeof a);
printf(“n%d”,sizeof r);
printf(“n%d”,sizeof s);
printf(“n%d”,sizeof e);
return 0;
}
Ans: 2 2 2 2
20. Identify the error in the following code?
static extern int a=5;
static int b = 6;
int main()
{
printf(“n%d”,a);
printf(“n%d”,b);
return 0;
}
Ans: 5 6
21. Identify the error in the following code?
#include<stdio.h>
int main()
{
extern int a=5;
printf(“n %d”,a);
return 0;
}
Ans: 5
22. Is it possible to declare static function in c language?
Ans: yes it become file scope function
23. Can we return more than one value by using return statement?
Ans: No
Ans: No
24. How to return more than one value from a function?
Ans: call by address
Ans: call by address
25. Can we use more than one return statement in one function?
Ans: yes
Ans: yes
26. Give an example for function returning void but contains return statement?
Ans: void abc()
{
printf(“Hello abc”);
return;
}
void main()
{
abc();
}
27. What is the differences between K&R C style and ANSI C style?
Ans: K&R-C
Ans: K&R-C
int sum(a,b) int a; int b;
{
return (a+b);
}
ANSII-C
int sum(int a,int b)
{
return (a+b);
}
28. Write a small ‘c’ function to receive any number of arguments?
Ans: variable Argument list concept
Ans: variable Argument list concept
No comments:
Post a Comment