Assignment Ques PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Some programs in C to try out for Pointers

1. Write a C program to add two numbers using pointers.

2. What is the output of the following program.


main()
{
char *p=“hai friends”,*p1;
p1=p;
while(*p!=‘\0’) ++*p++;
printf(“%s %s”,p,p1);
}

3. What is the output of the following program.


#include <stdio.h>
#define a 10
main()
{
#define a 50
printf(“%d”,a);
}

4. What is the output of the following program.


main()
{
int i, n;
char *x = “girl”;
n = strlen(x);
*x = x[n]; for(i=0;
i<n; ++i)
{
printf(“%s\n”,x);
x++;
}
}

5. What is the output of the following program.


main()
{
char *str1=“abcd”;
char str2[]=“abcd”;
printf(“%d %d %d”,sizeof(str1),sizeof(str2),sizeof(“abcd”));
}

6. What is the output of the following program.


main()
{
char not;
not=!2;
printf(“%d”,not);
}

7. What is the output of the following program.


main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++; q++;
r++;
printf(“%p...%p...%p”,p,q,r);
}
8. What is the output of the following program.
# include<stdio.h>
aaa()
{
printf(“hi”);
}
bbb(){
printf(“hello”);
}
ccc(){
printf(“bye”);
}
main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}
9. In the following pgm add a stmt in the function fun such that the address of ‘a’ gets
stored in ‘j’.
main(){ int
* j;
void fun(int **);
fun(&j);
}
void fun(int **k) {
int a =0;
/* add a stmt here*/
}

10. What is the output of the following program.


main()
{
int a[10];
printf(“%d”,*a+1-*a+3);
}

11. Program to find the maximum number in array using pointer.

12. Program to show call by reference.


13. Write a program for removing the duplicate element in an array.

14. Write a program to return more than one value from user defined function.
15. What is the output of the following program.

void main()
{
int const * p=5;
printf("%d",++(*p));
}
16. What is the output of the following program.
main()
{
int c[ ]={2.8,3.4,4,6.7,5};

int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(“ %d ”,*c);
++q; }
for(j=0;j<5;j++){
printf(“ %d ”,*p);
++p; }
}

17. What is the output of the following program.


main()
{
Char *p;
p=“Hello”;
printf(“%c\n”,*&*p);
}

18. What is the output of the following program.


main( )
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u
%u %u %d \n”,a+1,*a+1,**a+1,***a+1);
}

19. What is the output of the following program.

main( )
{
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;
ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
}
20. What is the output of the following program.
#define prod(a,b) a*b
main()
{
Int x=3,y=4;
printf(“%d”,prod(x+2,y-1));
}

You might also like