100% found this document useful (2 votes)
196 views

1D Array and String: #Include Int Void Char Char

This document contains 16 multiple choice questions about 1D arrays and strings in C programming. The questions cover topics such as string manipulation functions like strcpy, strcat, sizeof, pointers to strings, array indexing and increment/decrement operations on arrays and pointers. The correct answers to each question are also provided.

Uploaded by

mayande rohini
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
196 views

1D Array and String: #Include Int Void Char Char

This document contains 16 multiple choice questions about 1D arrays and strings in C programming. The questions cover topics such as string manipulation functions like strcpy, strcat, sizeof, pointers to strings, array indexing and increment/decrement operations on arrays and pointers. The correct answers to each question are also provided.

Uploaded by

mayande rohini
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1D Array and String

1.
#include<stdio.h>
int main(void)
{
char s[]={'a','b','c','\n','c','\0'};
char *p=NULL,*str=NULL,*str1=NULL;

p=&s[3];
str=p;
str1=s;

printf("%d",++*p + ++*str1-32);
return 0;
}

A. 77
B. 88
C. 76
D. 75

Answer: A

2.
#include<stdio.h>
#define so(s) sizeof(s)
int main(void)
{
char *s1="DESD",s2[]="desd";

printf("%d%d%d",sizeof(s1),sizeof(s2),so("DESD"));
return 0;
} //Consider 64 bit Compiler
A. 2 5 5
B. 8 8 8
C. 1 5 5
D. 8 5 5

Answer: D

Augest 2019 – December 2019 1


1D Array and String
3.
#include<stdio.h>
int main(void)
{
char *courses[]={ "PG-DAC","PG-DESD","PG-DMC",
"PreCAT","PG-DBDA"},*temp=NULL;
int i;
temp = courses[3];
courses[3] = courses[4];
courses[4] = temp;
for(i=0; i<=4; i++)
printf("%s,", courses[i]);

return 0;
}
A. PG-DAC,PG-DESD,PG-DMC,PreCAT,PG-DBDA,
B. PG-DAC,PG-DESD,PG-DBDA,PreCAT,PG-DMC,
C. PG-DAC,PG-DESD,PG-DMC,PG-DBDA,PreCAT,
D. Compile time error.

Answer: C

4.
#include<stdio.h>
int main(void)
{
void *vp=NULL; char ch='S',*cp="sunbeam"; int j=1;
vp = &ch; printf("%c", *(char *)vp);
vp = &j; printf("%d",*(int *)vp);
vp = cp; printf("%s",(char *)vp + 3);
return 0;
}
A. G20beam
B. S1beam
C. sunbeam
D. Sun
Answer: B

Augest 2019 – December 2019 2


1D Array and String
5.
#include<stdio.h>
#define max 5
#define int arr1[max]
int main(void)
{
typedef char arr2[max];
arr1 list={0,1,2,3,4};

arr2 name="name";
printf("%d %s",list[0],name);

return 0;
}

A. Compiler error
B. 0
C. 0 name
D. 1 name

Answer: A

6.
#include<stdio.h>
int main(void)
{
char a[]="12345\0"; int i=strlen(a);

printf("here in 3 %d\n",++i);
return 0;
}

A. here in 3 5
B. here in 3 6
C. here in
D. None of the above

Answer: B

Augest 2019 – December 2019 3


1D Array and String
7.
#include<stdio.h>
int main(void)
{
char a[100];
a[0]='a';a[1]='b';a[2]='c';a[4]='d';
abc(a);

return 0;
}
abc(char a[])
{
a++; printf("%c",*a);
a++; printf("%c",*a);
}

A. ac
B. bc
C. cc
D. cd

Answer: B

8.
#include <stdio.h>
int main(void)
{
char str[] = "PrecatQuiz";
printf("%s %s %sn", &str[5], &5[str], str+5);
printf("%c %c %cn", *(str+6), str[6], 6[str]);
return 0;
}
A. Runtime Error
B. Compiler Error
C. uiz uiz uiz u u u
D. tQuiz tQuiz tQuiz nQ Q Qn

Answer: D

Augest 2019 – December 2019 4


1D Array and String
9.
#include <stdio.h>
int fun(char *str1)
{
char *str2 = str1;
while(*++str1);
return (str1-str2);
}
int main(void)
{
char *str = "SunbeamPuneKarad";
printf("%d", fun(str));
return 0;
}
A. 15
B. -15
C. 14
D. 16

Answer: D

10.
#include <stdio.h>
int main(void)
{
int str[]={'P','R','E','C','A','T'};
printf("A%c ",str);
printf("A%s ",str);
printf("A%c ",str[0]);
return 0;
}

A. A A A
B. A AP AP
C. A [Garbage Value] AP AP
D. Compiler error

Answer: C

Augest 2019 – December 2019 5


1D Array and String
11.
#include <stdio.h>
int main(void)
{
char str[] = "%d %c";
char arr[] = "PreCAT@SUNBEAM";
printf(str, 0[arr], 2[arr + 3]);

return 0;
}

A. Compiler error
B. 80 101
C. P 84
D. 80 T

Answer: D

12.
#include <stdio.h>
int main(void)
{
char city[]="PUNE";
char *ptr=city;

while(*ptr != '\0')
{
printf("%c", *ptr); ptr++;
};
return 0;
}

A. P
B. PUNE
C. Compiler error
D. None of the above

Answer: B

Augest 2019 – December 2019 6


1D Array and String
13.
#include <stdio.h>
int main(void)
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;

i = ++a[1];
j = a[1]++;
m = a[i++];

printf("%d, %d, %d", i, j, m);


return 0;
}

A. 3,2,15
B. 2,3,20
C. 2,1,15
D. 1,2,5

Answer: A

14.
#include <stdio.h>
#include<string.h>
int main(void)
{
char s2[40]="Sunbeam",s1[20]=" IT Park Hinjawadi";

printf("%s", strcpy(s1, strcat(s2, s1)));


return 0;
}
A. Sunbeam IT Park Hinjawadi
B. IT Park HinjawadiSu IT Park Hinjawad
C. IT Park HinjawadiSunbeam
D. complie time error

Answer: A

Augest 2019 – December 2019 7


1D Array and String
15.
#include <stdio.h>
#include<string.h>
int main(void)
{
char p;
char buf[10] = {48, 49, 50, 50, 51, 52, 53, 54};

p = (buf + 1)[5];
printf("%c %d", p, p);

return 0;
}

A. 53 53
B. 53 5
C. 5 5
D. 5 53
E. Compile time error

Answer: D

16.
Choose a correct C Statement about Strings.

A. printf is capable of printing a multi word string.


B. Puts is capable of printing a multi word string.
C. Gets is capable of accepting a multi word string
from console or command prompt
D. All of the above

Answer : D

Augest 2019 – December 2019 8

You might also like