Pointers Practice Sheet
Pointers Practice Sheet
1.What do you mean by pointer? Why do we need it? Explain how data is link with
pointer with suitable examples.
2. Array name is considered a constant pointer. Justify this statement.
3. Explain how array elements will be accessed using an external pointer?
4. Write a menu driven C Program to perform the following operations using pointer
on a one Dimensional array of size 8.
a) Count how many even numbers are in this array.
b) Print all odd numbers in this array.
c) Search a number entered by user.
d) Delete a number from this array.
5. How we can access, use and print every character of a string using pointer? Explain
with suitable example.
6. Write a menu Driven C Program to perform the following operations on String
using pointer:
a) Find length of a string.
b) Reverse the string.
c) Check for string palindrome.
d) Count a particular character entered by user.
7. Explain every statements of this program: Write Output if statement is correct if not
write the reason behind it.
void main()
{
char s[30]=”HELLO TO GLA UNIVERSITY”
printf(“%c, s+2);
printf(“%c”, *(s+3));
printf(“%s”, s+2);
printf(“%d”, s+4);
printf(“%d”, *(s+4));
printf(“%s”, s+4);
printf(“%s”, *(s+4));
}
<5 5000
6-10 10000
>10 15000
1. void main()
{
int *ptr=10;
printf(“the value of ptr is %d”,*ptr);
}
2. void main()
{
int a=5, *b=&a;
printf(“d”,a*b);
}
3. void main()
char *c;
float x=10;
c=&x;
printf(“%d”,*c);
4. void main()
int a=10;
float *p=&a;
printf(“%d%d”,a,*p);
5. void main()
{
int a=5, *b=&a;
printf(“d”,a**b);
}
6. void main()
{
int a;
*&a=50;
printf(“%d”,a);
}
7. void main()
{
int i=50;
int * j=&i;
printf(“%d”,++(*j));
}
8. void main()
{
int x,*p;
p=&x;
*p=2;
printf(value of x is”,x);
}
9. void main()
int a=10;
int *ptr=&a;
printf(“%d %d”,++*ptr,*ptr++);
int num=5,*p=&num,x=*p;
printf(“%d %d %d”,++num,x+2,*p--);
printf("%c\n", *(s+1));
printf("%c\n", *s+1);
printf("%s\n", *(s+1));
void main()
int *p;
p = ary + 3;
*p = 5;
printf("%d\n", ary[3]);
void main()
int *p = ary + 3;
printf("%d\n", p[-2]);
}
6. #include <stdio.h>
void main()
strcpy(strc, str);
printf("%s\n", strc);
7. #include <stdio.h>
int main()
{
char a[2][6] = {"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}
8. #include <stdio.h>
int main()
return 0;
9. #include<stdio.h>
main()
{
int a[2][3]={ 10,20,30,40,50,60};
int i,j;
for(i=0;i<3;++i)
{
printf(“\n”);
for(j=0;j<3;++j)
printf(“%d”,*(*a+i)+j));
}
}
10. #include<stdio.h>
void main()
char str[]=”ABCDEF”;
printf(“%d”,(&str[3]-&str[0]);
1. #include<stdio.h>
int main()
{
char str[] = "peace";
char *s = str;
printf("%s\n", s++ +3);
return 0;
}
2. #include<stdio.h>
int main()
{
char str1[] = "India";
char str2[] = "BIX";
char *s1 = str1, *s2=str2;
while(*s1++ = *s2++)
printf("%s", str1);
printf("\n");
return 0;
}
3. #include<stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s", **p+1);
return 0;
}
4. #include<stdio.h>
void main()
int a[]={1,2,3,4,5};
int *p=a;
int *p2;
p2=p*2;
printf(“%p”,p2);
5. #include<stdio.h>
void main()
int a,*b,**c;
a=6;
**c=20;
*b=**c;
printf(“%d %d %d”,a,*b,**c);
6. #include<stdio.h>
void main()
int x[]={1,2,3,4,5,6};
int *p,y;
p=x+4;
y=p-x;
printf(“%d”,y);
7. #include<stdio.h>
int main ()
int i, *ptr;
ptr = var;
i = 0;
printf(“%d\t”,*ptr);
ptr++;
i++;
return 0;
8. #include<stdio.h>
void main()
char *x[ ] = {"hello", "goodbye", "so long", "thanks for all the fish"};
char *y;
int i;
for(i=0;i<4;i++)
{
y = x[i]; while(*y!='\0')
printf("\n");
1. #include <stdio.h>
k++;
k[2] = 'm';
void main()
f(s);
printf("%c\n", *s);
2. #include <stdio.h>
int * function();
void main()
int *(*ptr)();
ptr=&function;
x=(*ptr)();
printf("%d",*x);
int *function()
return &a;
3. #include <stdio.h>
void *vptr;
vptr = &i;
fun(vptr);
return 0;
int **q;
q = (int**)&p;
printf("%d\n", **q);
}
4. #include<stdio.h>
*sum=a+b;
*diff=a-b;
void main()
int a=10,b=20,sum,diff;
Sum(a,b,&sum,&diff);
5. #include <stdio.h>
return a * b * c;
void main()
function_pointer = mul;
function_pointer(2, 3, 4));
6. #include <stdio.h>
return a+b;
void main()
ptr=add;
printf(%d\n”,ptr(2,3));
printf(“%d”,(*ptr)(2,3);
7. #include <stdio.h>
int main ()
ptrMaxFunctin = retMax;
return 0;
}
8. #include<stdio.h>
return a+b;
return a-b;
return a*b;
return a/b;
void main()
int (*ptr[4])(int,int)={add,sub,mul,div};
int I;
for(i=0;i<4;i++)
p=(int *)malloc(sizeof(int)); }
} {
void main()
7. #include<stdio.h>
{
void main()
char *p;
{
p=(char *)malloc(6);
int a=10;
strcpy(p,”Hello”);
void *p=&a;
puts(p);
int *ptr=p;
p=(char *)realloc(p,15);
printf(“%u”,*ptr); printf(“Hello\n”);
} if(r)
{ printf(“world\n”);
char *p=NULL; }
char *r=0;