Q1. How would you declare a pointer variable ptr so that it can not be used to modify the string it points to (although ptr itself can be changed to point to some other string)?
Ans:
char * const ptr = "Hello";
Q2. How are the string literals are processed by compiler?
Ans:
String literals are allocated in data area that may be read-only.
Q3.
int a[25];
int * p = a + 3;
Which one of the following is equivalent to the above code snippet?
a) int a[25];
int *p = &a[3];
b) int a[25];
int * p = &(a + 3);
c) int a[25];
int * p = (&a)[3];
d) int a[25];
int * p = &a[2];
e) int a[25];
int * p = a[3];
Ans:
e)
Q4. How would you declare a constant pointer to a constant string?
Ans:
const char * const ptr;
Q5. Find the o/p:
int divider(double m, double n)
{
return m/n;
}
main()
{
printf("%d", divider(10/3);
}
Ans:
3
Q6. Find the o/p:
main(){
struct xx{
char name[]="hello";
};
struct xx *s;
printf("%s",s->name);
}
Ans:
Compiler Error
Explanation:
You should not initialize variables in structure declaration.
Explanation:
You should not initialize variables in structure declaration.
Q7. Find the o/p:
void main()
{
int const *p=5;
printf("%d",++(*p));
}
Ans:
Compiler error: Cannot modify a constant value.
Q8. Find the o/p:
# include < stdio.h >
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
Ans:
I hate U
Q9. Find the o/p:
#include <stdio.h>
main() {
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
Ans:
5 4 3 2 1
Q10. Find the o/p of this:
main(){
extern int i;
i=20;
printf("%d",i);
}
Ans:
Linker Error : Undefined symbol '_i'
Q11. Find the o/p:
main(){
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}
Ans:
1 4
Q12. Find the o/p:
main(){
char string[]="Hello World";
display(string);
}
void display(char *string){
printf("%s",string);
}
Ans:
Compiler Error : Type mismatch in redeclaration of function display
Q13. What is output?
main(){
int i=10;
i=!i>14;
printf("i=%d",i);
}
Ans:
i=0
No comments:
Post a Comment