0% found this document useful (0 votes)
11 views14 pages

Arraypointerstringque 1

The document contains multiple C programming code snippets, each demonstrating various operations with pointers, arrays, and string manipulations. The snippets include examples of modifying values in arrays, printing characters and strings, and using pointer arithmetic. Overall, the document showcases a range of programming techniques and behaviors in C.

Uploaded by

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

Arraypointerstringque 1

The document contains multiple C programming code snippets, each demonstrating various operations with pointers, arrays, and string manipulations. The snippets include examples of modifying values in arrays, printing characters and strings, and using pointer arithmetic. Overall, the document showcases a range of programming techniques and behaviors in C.

Uploaded by

G.satheesh Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

1]

int main()
{
int a[5]={321,322,323,324,325};
char *p=(char *)a+2;
short int *q=p+2;
p[-1]=49;
q[-1]=50|51<<8;
p[3]=0;
printf("%s\n",a);
}

2]
int main()
{
char s[20]="ABCDEF";
char *p="1234";
short int *q=(short int *)(s+1);
q[2]=p[2]|(50<<8);
q[3]=0;
printf("%s\n",s);
}

3]
int main()
{
int a[5]={10,20,30,40,50};
char *p=(char *)a+9;
p[-4]=1;
short int *q=a;
q+=2;
printf("%d\n",*q);
}

4]
int main()
{
char *p="Abcdef"+2;
while(*++p);
printf("%c\n",++*p);
}

5]
int main()
{
int i;
short int a[5]={1,2,3,4,5};
int *p=a+1;
++p;
p[-1]=258;
for(i=0;i<5;i++)
printf("%d ",a[i]);}
6]
int main()
{
char s[]="Abcdefgh";
int *p=s+1;
p++;
*p&=0x0000ff00;
*p|=49;
printf("%s\n",s);
}

7]
void main()
{
int num=0xABCD;
char *p=&num;
++p;
printf("%x\n",*p);
p[-1]&=(~(1<<7));
printf("%d",*--p);
}

8]
void main()
{
int i=0;
int a[5]={1,2,3,4,5};
int *p=a;
while(i<3)
{
p[i]=p[i]+10;
i++;
p++;
}
for(i=0;i<5;i++)
printf("%d ",a[i]);
}

9]
void main()
{
int num=155;
short int *p=&num;
char *q=&num;
*p|=(65<<8);
p[1]|=(66<<8)|(50);
num=num>>8;
q[3]=0;
printf("%s\n",q);
}
10]
void main()
{
int a[5]={321,322,323,324,325},j;
char *p=&a+1;
p=p-8;
j=++*p;
printf("%d\n",j);
j=--*++p;
printf("%d\n",j);
j=*p++;
printf("%d\n",j);
j=(*p)++;
printf("%d\n",j);
printf("%x\n",a[3]);
}

11]
void main()
{
int a[5]={0};
short int *p=a+1;
char *q=p+1;
*++p=0xAB;
a[1]|=a[1]>>16;
printf("%d\n",*q);
printf("%d\n",*(q-2));
}

12]
void main()
{
char *p="abcdef";
p="123456";
printf("%d\n",-2[p+2]);
printf("%c\n",(p++)[1]);
printf("%d\n",1[p+1]);
printf("%d\n",*p);
}
13]
void main()
{
char s[]="ABCDE12",ch;
char *p=s+1;
ch=*p++;
printf("%c\n",ch);
ch=++*p;
printf("%c\n",ch);
ch=++*p++;
printf("%c\n",ch);
ch=++*--p;
printf("%c\n",ch);
*p=0;
printf("%s\n",s);
}

14]
void main()
{
int i=0;
char *p;
p=strstr("Abcde","");
p++;
++*p;
printf("%s\n",p);
}

15]
void main()
{
char str[]="ABCDEF123";
int *p=(int *)str+1;
*p^=((0xFF)<<24);
printf("%o\n",*p);
}

16]
void main()
{
char str[]="1234";
char *p="Abcde";
p=str;
++*++p;
printf("%s\n",str);
}
17]
void main()
{
printf("%s\n","ABCDE"+1);
printf("%c\n",("ABCDE"+1)[-1]);
printf("%c\n",*("ABCDE"+2));
printf("%c\n","ABCDE"[3]);
}

18]
void main()
{
char a[]="abcde";
char *p="12345";
a="Pqrst";
printf("%s\n",a);
}

19]
void main()
{
char a[]="abcde";
char *p="12345";
p="Pqrst";
printf("%s\n",p);
}

20]
void main()
{
int a[5]={400,500,600,700,450},i;
char *p=a+1;
while(*p)
{
printf("%d\n",*p);
p++;
}
}
21]
void sum(int *p,int *q)
{
while(*p!=51)
{
++*++p;
--*q;
}
}

void main()
{
int a[5]={10,20,30,40,50},ele,i;
ele=sizeof(a)/sizeof(a[0]);
sum(a+2,&ele);
for(i=0;i<ele;i++)
printf("%d ",a[i]);
}

22]
void main()
{
char a[]="abcde";
char *p="12345";
p="Pqrst";
++*++p;
printf("%s\n",p);
}

23]
void main()
{
char s[]={'A','B','C','D','E','F'};
short int *p=s+1;
p[1]=50;
printf("%s\n",s);
}
24]
void print(char *p,int *q)
{
int i=0;
while((p[i]>='0') && (p[i]<='9'))
{
i++;
--*q;
}
}
void main()
{
char s[]="1234#5678";
int i=0;
for(i=0;s[i];i++);
print(s,&i);
s[i-1]=65;
printf("%s",s);
}

25]
int sum(int a,int b)
{
a++;
b++;
return a,b;
}

void main()
{
int c;
c=sum(10,20);
printf("%d\n",c);
}

26]
void main()
{
int a[5]={10,20,30,40,50},i;
for(i=0;i<5;i++)
{
printf("%d\n",*a);
++a;
}
}
27]
void main()
{
int a[5]={10,20,30,40,50},i;
for(i=0;i<5;i++)
{
printf("%d",*a);
}
}

28]
void main()
{
const int a[5]={10,20,30,40,50};
int i=0;
int *p=a+1;
for(;i<5;i++)
++*p;
for(i=0,p=a;i<5;i++)
printf("%d\n",p[i]);
}

29]
void sum(int a,int *b)
{
a=20;
*b=50;
}
void main()
{
int a=10,b=30;
sum(a,&b);
printf("a=%d b=%d\n",a,b);
}

30]
void main()
{
int a[5]={384,400,430,450,500};
char *p=&a+1;
--p;
printf("%d",p[-7]);
}
31]
void main()
{
int num=0xABCDEF;
char *p=&num;
short int *q=p+1;
q[0]=p[3];
printf("%d\n",num);
}

32]
void print(char *p)
{
while(*p)
{
*p=*p^32;
++p;
}
}
void main()
{
char s[]="ABCDE";
print(s);
printf("%s",s);
}

33]
void print(char *p)
{
while(*p)
{
*p=*p^32;
p++;
}
}

void main()
{
char *p="ABCDE";
print(p);
printf("%s\n",p);
}

34]
void main()
{
char *p;
strcpy(p,"ABCD");
printf("%s\n",p);
}
35]
void main()
{
char *p="ABCDE";
strcpy(p,"1234");
printf("%s\n",p);
}

36]
void main()
{
char str[]="ABCDE";
char *p=str;
strcpy(p,"1234");
printf("%s\n",p);
}

37]
void main()
{
char str1[15]="Good ";
char str2[]="Evening";
strcpy(str1+strlen(str1),str2);
printf("%s\n",str1);
}

38]
void main()
{
char str[]="ABCDE1234";
str=str+5;
printf("%s\n",str);
}

39]
void print(char *str)
{
str=str+5;
printf("%s\n",str);
str[-3]=70;
str[-2]=32;
str[2]='0';
}
void main()
{
char str[]="ABCDE1234";
print(str);
printf("%s\n",str);
}
40]
void main()
{
char *p="12345";
char str[]="ABCDE";
p=str;
++*++p;
p[2]=50;
printf("%s\n%s\n",str,p);
}

41]
void main()
{
char str[]="ABCD""PQRS";
char *p=str+3;
*++p=50;
printf("%s\n",str);
}

42]
void main()
{
char str1[]="ABCDE";
char str2[20];
strcpy(str2,str1);
if(str1==str2)
printf("Same\n");
else
printf("Different\n");
}

43]
void main()
{
short int a[5]={0245,0256,0777,04567,0123};
unsigned char *p=a+1;
char *q;
p[3]=1<<7;
p=p+3;
q=p;
printf("%d\n",*p);
printf("%d\n",*q);
}

44]
void main()
{
char str[]="ABCDE";
printf("%d\n",sizeof(str));
printf("%d\n",strlen(str));
}
45]
void main()
{
int a=400;
char *p=&a;
*++p=1;
*--p=2;
printf("%d\n",a);
}

46]
void main()
{
char str[]={65,68,69,71,75,52,0};
printf("%s\n",str);
}

47]
void main()
{
char str[]="ABCDEF";
short int *p=str;
printf("%o %o\n",p[0],p[1]);
}

48]
void main()
{
if(((strlen("ABCD"))-(strlen("1234567")))>1)
printf("Hello\n");
else
printf("Bye\n");
}

49]
void main()
{
char *str1="ABCDE";
char *str2="12345";
strcat(str1,str2);
printf("%s\n",str1);
}

50]
void main()
{
char str1[20]="ABCDE";
char *str2="12345";
strcat(str1,str2);
printf("%s\n",str1);
}
51]
void main()
{
int a[5]={0xFF,0xAB,0xFFcd,0x1234};
short int *p=&a[3,2];
printf("%d\n",*p);
printf("%x\n",*p);
printf("%o\n",*p);
}

52]
void main()
{
int a[5]={0,1,2,3,4};
char *p=&a+1[a];
short int *q=(&a+1)[2];
printf("%d\n",q-(short int *)p);
}

52]
void main()
{
int a[5]={300,350,400,450,500},i;
char *p=a+1;
for(i=0;i<5;i++,p++);
printf("%d",p[3]);
}

53]
void main()
{
int a[5]={10,20,30,40,50},i=0;
short int *p=a;
while(++i<5)
{
++p;
}
printf("%d\n",p-(short int *)a);
}

54]
void main()
{
unsigned char a[]={250,128,127,123,129};
unsigned char *p=&a+1;
while(++p[-5])
{
printf("%d\n",p[-5]);
}
}
55]
void main()
{
char a[]={120,121,122,123,125};
char *p=&a+1;
p[-3]=120;
while(++*(p-3)>0)
printf("%d\n",p[-3]);
}

56]
void main()
{
int a[]={255,350,384,400,450};
char ch=259;
int *p=&a+1;
while(--p,ch--);
printf("%d\n",*p);
}

You might also like