Pointer in C Language
This Test will cover Pointer in C Langauge, including declaraction and initialization of pointer, pointer arithmetic, function pointer, pointer to array etc.
Q. If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
Q What will be the output of following code?
#include<stdio.h>
main()
{
float a = 10.2;
int *p = a;
printf("%d",*p);
}
Q. The operator used to access the value of variable at address stored in a pointer variable is?
Q. What will be the output of following code assuming that array begins at location 1002?
#include<stdio.h>
main()
{
int a[5] = {1, 2, 3, 4, 5};
int *p = a;
printf("%d\t%d\t%d\t%d\t",*p,0[a],a,p);
}
Q. What will be the output of following code?
#include <stdio.h>
int arr[] = {1,2,3};
main()
{
int *ptr;
ptr = arr;
ptr = ptr+3;
printf("%d",*ptr);
}
Q. What will be the output of following code?
#include <stdio.h>
void main()
{
int const *p = 5;
printf("%d", ++(*p));
}
Q What will be the output of following code?
#include<stdio.h>
main()
{
struct std
{
int x = 3;
char name[] = "hello";
};
struct std *s;
printf("%d", s->x);
printf("%s", s->name);
}
Q. What will be the output of following code?
#include <stdio.h>
main()
{
register i = 5;
char j[] = "hello";
printf("%s %d", j, i);
}
Q. What is the size of char on 32-bit machine?
Q Is the NULL pointer same as an uninitialised pointer?
Q. Which of the statement is correct about the code?
int sum(int, int);
int (*s)(int, int);
s = sum;
Q What will be the output of following code?
#include <stdio.h>
int fun(int *a,int *b)
{
*a = *a+*b;
*b = *a-*b;
*a = *a-*b;
}
main()
{
int x = 10,y = 20;
fun(&x,&y);
printf("x= %d y = %d\n", x, y);
}