String Q-A
Ques 1. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void ustrcpy(char *d, char *s);
int main()
{
char name1[15] ="hello";
char name2[15] ="ptinstitute.in";
ustrcpy(name1, name2);
printf("\n %s", name2);
return 0;
}
void ustrcpy(char *d, char *s)
{
d=s;
}
options:
A. ptinstitute.in
B. compiler error
C. runtime error
D. not print anything
Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void ustrcat(char d[], char s[]);
int main()
{
char name1[15] = "good";
char name2[15] ="ptinstitute.in";
ustrcat(name1, name2);
printf("\n %s", name1);
return 0;
}
void ustrcat(char d[], char s[])
{
int len1, len2,i;
len1=strlen(d);
len2=strlen(s);
for(i=len1; i
Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char name1[] = {'g', 'o', 'o', 'd'};
char name2[] ="ptinstitute.in";
printf("\n %d %d", sizeof(name1), sizeof(name2));
printf(" %d", sizeof(name1[1]));
return 0;
}
options:
A. 5 15 1
B. compiler error
C. 5 14 3
D. 4 15 1
Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void ustrcpy(char *, char *);
int main()
{
char name1[15];
char name2[] ="ptinstitute.in";
ustrcpy(name1, name2);
printf("\n name1 = %s", name1);
printf(" name2 = %s", name2);
return 0;
}
void ustrcpy(char *d, char *s)
{
int i;
for(i=0; i
Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char name1[] = {'g', 'o', 'o', 'd','j','k'};
char name2[] ="ptinstitute.in";
int ii[]={2,3,4,5,6,7,8};
printf("\n %d %d", sizeof(name1), sizeof(name2));
printf(" %d", sizeof(&name1));
return 0;
}
options:
A. 7 15 4
B. compiler error
C. 4 4 4
D. 6 15 4
Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
char *str;
void fun(char *s);
int main()
{
strcpy(str, "ptinstitute.in");
fun(str);
printf("\n %s",str);
return 0;
}
void fun(char *s)
{
printf(" %s",s);
}
options:
A. compiler error
B. runtime error
C. ptinstitute.in ptinstitute.in
D. ptinstitute.in
Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void fun(char *s);
int main()
{
char *s1 = "hello";
char *s2= "good";
while(s1!= s2)
fun(s1);
return 0;
}
void fun(char *s)
{
printf("\n %s",s);
}
options:
A. compiler error
B. Infinite loop
C. hello
D. good
Ques 8. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *s1 = "hello";
char *s2 = "good";
printf("\n %d", s2-s1);
return 0;
}
options:
A. 6
B. 111
C. o
D. compiler error
Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s1[] = "welcome";
char *s2=s1;
s2 =s2[1] -s2[3];
printf("\n %s",s2);
return 0;
}
options:
A. runtime error
B. compiler error
C. 2
D. lcome
Ques 10. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s1[] = "welcome";
printf("\n %s %s",&s1[1], &s2[2]);
return 0;
}
options:
A. run time error
B. elcome lcome
C. compiler error
D. welcome welcome
Ques 11. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s1[] = "welcome";
printf("\n %c %c %c",*(s1+1), s1[2], 3[s1]);
return 0;
}
options:
A. compiler error
B. e l c
C. runtime error
D. elcome lcome come
Ques 12. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s1[] = "welcome";
printf("\n %s %s", s1+3, s1+s1[1]-s1[6]);
return 0;
}
options:
A. welcome welcome
B. come welcome
C. compiler error
D. runtime error
Ques 13. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s1[1][1][2][4] = {'w', 'e', 'l', 'c', 'o', 'm', 'e', '\0'};
printf("\n %s ", ***s1);
return 0;
}
options:
A. welcome
B. compiler error
C. runtime error
D. welcom
Ques 14. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i=0;
int len;
char *s1 = "welcome";
char *p;
p=(char *)malloc(10);
len=strlen(s1);
do{
p[i] = s1[++i];
}
while(i
Ques 15. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
char * changecase(char *s2)
{
char *t= (char *)malloc(15);
int i;
for(i=0; i<15; i++)
{
if(s2[i] >= 65 && s2[i]<97)
t[i]=s2[i]+32;
else
t[i]=s2[i];
}
t[i]=0;
return t;
}
int main()
{
char *s1 = "PTINSTITUTE.IN";
char *t=changecase(s1);
printf("\n %s", t);
return 0;
}
options:
A. PTINSTITUTE.IN
B. ptinstitute.in
C. compiler error
D. runtime error
Ques 16. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
void swap(int *p, int *q)
{
int t=*p;
*p=*q;
*q=t;
}
int main()
{
int p=33, q=55;
swap(&p,&q);
printf("\n%d, %d", p, q);
return 0;
}
options:
A. 33 55
B. 55 33
C. compiler error
D. runtime error
Answers
1. A
2. B
3. D
4. A
5. D
6. B
7. B
8. A
9. A
10. C
11. B
12. B
13. A
14. B
15. B
16. B