[go: up one dir, main page]

0% found this document useful (0 votes)
74 views2 pages

Pointer MCQ

The document contains multiple C programming code snippets, each demonstrating various concepts such as pointer manipulation, conditional statements, and type casting. The snippets illustrate different behaviors and outcomes when executing the code, often leading to unexpected results due to pointer arithmetic or type conversions. Overall, the document serves as a collection of examples for educational purposes in understanding C programming intricacies.

Uploaded by

dadmisangu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views2 pages

Pointer MCQ

The document contains multiple C programming code snippets, each demonstrating various concepts such as pointer manipulation, conditional statements, and type casting. The snippets illustrate different behaviors and outcomes when executing the code, often leading to unexpected results due to pointer arithmetic or type conversions. Overall, the document serves as a collection of examples for educational purposes in understanding C programming intricacies.

Uploaded by

dadmisangu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.#include<stdio.h> main() { int a=0,b=2,c=2; *(a?&b:&a)=(a?

b:c); printf("%d %d %d \n",a,b,c); }


2.#include<stdio.h> main() { int i=135; char *p=(char*)&i; printf("%d\n",++*p); }
3.#include<stdio.h> main() { int k=125; char *i = (char*)&k; for( ; *i>=0 ; ++*i ); printf("%d\n",
*i); }
4.#include<stdio.h> int main() { int a = 101; char *p = (char*)&a; *++p=5-2; *--p=5+2;
printf("%d \n",a); }
5.#include<stdio.h> int main() { int x = -512; unsigned char *p; p = &x; printf("%d\n",*p++);
printf("%d\n",*p); }
6.#include<stdio.h> int main() { int x=30, *y, *z; y=&x; /* Assume address of x is 500 and integer
is 4 byte size */ z=y; *y++=*z++; x++; printf("x=%d, y=%u, z=%u", x, y, z); return 0; }
7.main() { char *p; printf("%d %d",sizeof(*p),sizeof(p)); }
8.#include<stdio.h> int main() { const int x=5; const int *ptrx; ptrx = &x; *ptrx = 10; Printf("%d",
x); return 0; }
9.int main(){ float x; x=(float)3.5==3.5; printf("%f",x); return 0; }
10.main() { int i = 6; if( ((++i < 7) && ( i++/6)) || (++i <= 9)); printf("%d",i); }
11.#include<stdio.h> int main() { int a= 100, b=55; if(a!=100); a=200; if(a==100) a=300;
if(a==200) b=33; else b=22; printf("a-> %d b-> %d \n",a,b); }
12.#include<stdio.h> int main() { int i = -4 ,c=4; do { while(i) i++; c--; for(i;i++;i++,c++)
printf("Chennai \n"); break; }while(1); printf("i-> %d c-> %d \n", i,c ); }
13.#include<stdio.h> main() { int ami=0,i; for(i=0 ; i<5 ; i++) { ami++; continue; } printf("ami=
%d \n",ami); }
14.#include<stdio.h> main() { int i = 3, count =3; do { count++; while(i) i--; for(i++;--i;i++)
printf("Embedded System\n"); break; }while(1); printf("i=%d , count=%d \n", i,count); }
15.#include<stdio.h> int main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j:
printf("BAD"); break; } }
16.#include<stdio.h> int main(){ void *ptr; short int k= 477; ptr=&k; printf("%d \n",*(char *)ptr);
printf("%x \n",*(short int *)ptr); return 0; }
17.#include<stdio.h> int main(){ int i=11,j=22,k=33; int *p1=&i; int *p2=&j; int *p3=&k;
*p2=*p1+*p3; printf("%d \n",j); *p3=*p2+*p1; printf("%d \n",k); return 0; }
18.#include<stdio.h> int main(){ int RCB=0x345678; char *p=(char*)&RCB; printf("%d \n",*p);
p+=2; printf("%o \n",*p); return 0; }
19.#include<stdio.h> int main(){ int RCB=777; const int *p=&RCB; printf("%d \n",*p+111); return
0; } \
20.#include<stdio.h> int main(){ double *CSK=202; ++CSK; printf("%d\n",3+CSK); }
21.#include<stdio.h> int main(){ double d=-99.345; short int *p; p=(short int *)&d; p=p+3;
printf("%d\n",*p>>15&1); return 0; }
22.#include<stdio.h> int main(){ const int *ptr=(int *)025; printf("%d \n", ptr+'0'); return 0; }
23.#include<stdio.h> int main(){ int x=0x12345678; short int *p=&x; p=p+1; printf("%d \
n",*(char*)p); }
24.#include<stdio.h> main() { int arr[ ]={1.2, 2.4, 3.6, 4.8, 5.9}; int j, *ptr = arr; for(j = 0;j<5;j++) {
printf("%d ", *arr); ++ptr; } }
25.#include<stdio.h> int main() { int x = -512; unsigned char *p; p = &x; printf("%d\n",*p++);
printf("%d\n",*p); }
26.#include<stdio.h> int main() { int __=101; char *_=&__; *_=102; __=103; printf("%d \n",*_); }
27.#include<stdio.h> int main() { int *p,i,j; for(i=2;p=&i,*p;i--) printf("APJ\n"); if(i!=*p)
printf("Kalam\n"); }
28.#include<stdio.h> int main() { int a = 101; char *p = (char*)&a; *++p=5-2; *--p=5+2;
printf("%d \n",a); }
29.#include<stdio.h> int main() { int const *p,i=999; p=&i; *p++; printf("%d\n",i); }
30.#include<stdio.h> main() { int INT = 33; char *CHAR = &INT; *++CHAR = 1; --CHAR ;
printf("a-> %d , b-> %d \n", *CHAR , INT); }
31.#include<stdio.h> main() { int k=125; char *i = (char*)&k; for( ; *i>=0 ; ++*i ); printf("%d\n",
*i); }
32.#include <stdio.h> void main() { char s[10] = "hello"; s++; printf("%c \n", *s); }
33.#include<stdio.h> main() { const int aa=10; int *p=&aa; *p=11; printf("%d \n",*p); }
34.#include<stdio.h> main() { int i=135; char *p=(char*)&i; printf("%d\n",++*p); }
35.#include <stdio.h> int main() { const int ary[4] = {1, 2, 3, 4}; int *p; p = ary; *p = 5; printf("%d\
n", *ary); }
36.#include<stdio.h> char *str="char *str=%c vector %c \n"; int main() { printf(str,34,66); }
37.#include<stdio.h> int main() { char a[ ] = "12345678"; int *ptr = a; printf("%x %x\
n",ptr[0],ptr[1]); }
38.#include<stdio.h> int main() { int x = -512; unsigned char *p; p = &x; printf("%d\n",*p++);
printf("%d\n",*p); }
39.#include<stdio.h> int main() { int i=260; char *ptr=&i; *++ptr = 3; printf("%d\n",i); return 0; }
40.#include<stdio.h> main() { int i = 5; void *vptr; vptr = &i; printf("\nValue of iptr = %d \n",
*vptr); }
41.#include<stdio.h> main() { int a = 5; const int *ptr; ptr = &a; *ptr = 10; printf("%d\n", a); }
42.#include<stdio.h> main() { int *ptr; *ptr = 10000; printf("%d \n" , *ptr); }
43.#include<stdio.h> main() { char *ptr; char _12[] = "wellcome to vectorindia.org"; ptr = _12; ptr
+= 12; printf("%s \n",ptr); }
44.#include<stdio.h> main() { int a = 147; char *ptr; ptr = (char *)&a; printf("%d \n",*ptr); }
45.#include<stdio.h> main() { int arr[5] = { 1, 2, 3, 5, 7 }; int *ptr = (&arr + 1); printf("%d %d\n",
*(arr + 1), *(ptr - 1)); }
46.#include<stdio.h> main() { int a, b, c; int arr[] = {1,2,3,4,5,6,7,8}; a = ++arr[1]; b = arr[1]++; c=
arr[a++]; printf("%d--%d--%d \n", a, b ,c); }
47.

You might also like