0% found this document useful (0 votes)
167 views

Topic 4 Assignment Pointers and Strings

The document contains 25 questions about pointers and strings in C programming. It provides code snippets and asks for the output or evaluates if a program is correct. The questions cover topics like pointer arithmetic, string manipulation functions, arrays of pointers, multi-dimensional arrays, and string copying/concatenation.

Uploaded by

Shaorya Vijay
Copyright
© Attribution Non-Commercial (BY-NC)
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)
167 views

Topic 4 Assignment Pointers and Strings

The document contains 25 questions about pointers and strings in C programming. It provides code snippets and asks for the output or evaluates if a program is correct. The questions cover topics like pointer arithmetic, string manipulation functions, arrays of pointers, multi-dimensional arrays, and string copying/concatenation.

Uploaded by

Shaorya Vijay
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 8

Pointers and Strings

A) What will be the output of the following programs:1. #include<string.h>


main( )
{
char[s]= Rendezvous!);
printf(\n%d,*(s+strlen(s));
}
2. main( )
{
printf(5+ Fascimile);
}
3. main( )
{
charch[20];
int i;
for(i=0; i<19; i++)
*(ch + i) = \0;
printf( \n%s, ch);
}
4. main ( )
{
charstr[ ] ={48,48,48,48,48,48,48,48,48,48};
char *s;
int I;
s = str;
for(i=0;i<=9;i++)
{
if(*s)

printf(%c,*s);
s++;
}
}
5. main( )
{
char str1[ ]= Hello;
char str2[ ]= Hello;
if(str1==str2)
printf(\n Equal);
else
printf(\n Unequal);
}

6. main( )
{
char str[10]={ 0,0,0,0,0,0,0,0,0,0};
char *s;
int i;
s = str;
for ( i=0;i<=9;i++)
{
if(*s)
printf(%c, *s);
s++;
}
}

7. main ( )
{
printf(%c, abcdefgh[4]);
}
8. main ( )
{
charstr[7]= Strings;
printf(%s,str);
}
9. main ( )
{
char *str[ ]= {Frogs, Do, Not, Die, They, Croak! };
printf(%d%d, sizeof (str), sizeof (str[0]));
}
10.main ( )
{
char s[ ] = C smart!;
int i;
for(i=0;s[i];i++)
printf(\n%c%c%c%c, s[i], *(s+i), i[s], *(i+s));
}
11.main ( )
{
char s[ ] = Oinks Grunts and Guffaws;
printf(\n%c, *(&s[2]));
printf(\n%s, s+5);
printf(\n%s,s);
printf(\n%c, *(s+2));
printf(\n%u,s);
}

12.main ( )
{
chararr[ ]= Pickpocketing my piece of mind..;
int i;
printf(\n%c, *arr);
ar++;
printf(\n%c, *arr);
}
13.main ( )
{
charstr[ ] = Limericks;
char *s;
s = &str[6] 6;
while(*s)
printf(%c, *s++);
}
14.main ( )
{
static char *s[ ] = { ice, green, cone, please };
static char **ptr[ ] = { s+3, s+2, s+1, s};
char **p= ptr;
printf(\n%s, **++p);
printf(\n%s, *--*++p+3);
printf(\n%s, *p[-2]+3);
printf(\n%s, p[-1][-1] + 1);
}
15.main( )
{
charstr[ ] = For your eyes only;
int i;
char *p;
for( p = str, i=0; p+i<=str+strlen(str); p++,i++)
printf(%c, *(p+i));
}

16.main ( )
{
charstr[ ] = MalayalaM;
char *s;
s = str+8;
while(s>= str)
{
printf(%c, *s);
s--;
}
}
17.main ( )
{
char a[ ] = Able was I ere I saw elbA;
char *t, *s, *b;
s=a;
b=a+strlen(a) 1;
t=b;
while(s !=t)
{
printf(%c, *s);
s++;
printf(%c,*t);
t--;
}
}

18.main ( )

{
char s[ ]= C is a philosophy of life;
char t[40];
char *ss, *tt;
ss= s;
tt=t;
while(*ss)
*tt++ = *ss++;
*tt= \0;
printf(\n%s,t);
}
19.
main ( )
{
char s[ ]= Lumps, bumps, swollen, veins, new pains);
char t[40];
char *ss, *tt;
tt = t;
ss= s;
while(*tt++=*ss++);
printf(\n%s,t);
}
20.main ( )
{
intarr[12];
printf(\n%d, sizeof(arr));
}
21.main ( )
{
char *mess[] = {
Some love one,
Some love two, I love one, That is you };

printf(\n%d%d, sizeof(mess),sizeof(mess[1]));
}

22.main ( )
{
char names[3][20];
int i;
for(i=0;i<=2;i++)
{
printf(\n Enter name);
scanf(%s, names[i]);
printf(You have entered %s, names[i]);
}
}
23.main ( )
{
char names[5][20] = { Roshni, Manish, Mona, Baiju, Ritu
};
int i;
char *t;
t = names[3];
names[3] = names[4];
names[4] = t;
for (i=0; i <=4; i++)
printf(\n%s, names[i]);
}
24.main( )
{
char mess[6][30]= { Dont walk in front of me,
I may not follow,
Dont walk behind me,

I may not lead,


Just walk besides me,
And be my friend.};

printf(\n%c%c, *(mess[2]+9), *(*(mess+2)+9));


}

25.Is the following program correct ? YES/NO


main( )
{
char *str1=United;
char *str2=Front;
char *str3;
str3 = strcat(srt1,str2);
printf(\n%s,str3);
}

You might also like