C String Questions

Hello PrepSter,

If you find any errors in the quiz below kindly comment in the comment section and we will make it our priority to fix it.

Also if you have a better of the solution to the questions, please do comment them below and if we find it better than ours, we will post it in our website.

Question 1

Time: 00:00:00
What is the expected output of the following program ?
#include <stdio.h>
int main()
{
char str[] = "%d %c", arr[] = "PrepInsta";
printf(str, 0[arr], 2[arr +2]);
return 0;
}

P Q

P Q

80 Q

80 Q

80 73

80 73

Compilation error, because of incorrect initialization.

Compilation error, because of incorrect initialization.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
What will be printed by the following program ?
#include <stdio.h>
int main()
{
char p[] = "prepster";
char t;
int i, m, j;
for(i=0,j=(strlen(p)); i<j;m++, i++)
{
t=p[i];
p[i]=p[j-i];
printf("%c",p[i]);
}
return 0;
}

retsperp

retsperp

retsster

retsster

retster

retster

sterprep

sterprep

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
What will be printed by the code below given that the size of a char value is 1 byte.
#include<stdio.h>
int main()
{
char str[20] = "PrepSter";
printf ("%d", sizeof(str));
return 0;
}

9

9

8

8

20

20

19

19

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

Time: 00:00:00
What will be printed by the C code below ?
#include<stdio.h>
int main()
{
char str[20] = "PrepSter";
printf ("%c", str[11]);
return 0;
}

Compilation error.

Compilation error.

Some garbage value

Some garbage value

(null)

(null)

0

0

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

Time: 00:00:00
What is the output of the program below ?
#include<stdio.h>
int main()
{
char *str1 = "PrepSter";
char str2[] = "PrepSter";

printf("%d %d",
sizeof(str1), sizeof(str2));
return 0;
}

8 9

8 9

8 8

8 8

9 8

9 8

8 7

8 7

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
If fun("Prep Insta") is called in the main function, what will be printed by the following code ?
void fun(char *a)
{
if (*a && *a != ` `)
{
fun(a+1);
putchar(*a);
}
}

Prep

Prep

Prep Insta

Prep Insta

perP

perP

atsnI preP

atsnI preP

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

Time: 00:00:00
What is the output of the following program ?
#include<stdio.h>
int main()
{
char arr[7] = "12345", *p;
p = arr + 2;
*p = '0' ;
printf ("%s", arr);
}

12045

12045

(null)

(null)

12300

12300

10345

10345

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

Time: 00:00:00
What is the correct output of the given program ?
#include <stdio.h>
struct ch
{
char x, y, z;
};
int main()
{
struct ch p = {'l', '0', 'x' + 2};
struct ch *q = &p;
printf("%c, %c", *((char *)q + 1), *((char *)q + 2));
return 0;
}

l +1, x+2

l +1, x+2

0, z+2

0, z+2

0, z

0, z

'0', 'z'

'0', 'z'

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
What is the correct output of the code given below ?
#include <stdio.h>
int main()
{
char str[] = "raajpoppla";
int i=1;
for(i=1;i<strlen(str);i++)
{
if(str[i]==str[i-1])
{
printf("%c",str[i-1]);
}
}
return 0;
}

rajpopla

rajpopla

aapp

aapp

rjpola

rjpola

ap

ap

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
What is the output of the C code below ?
#include <stdio.h>
int main()
{
char *s1 = (char *)malloc(50);
char *s2 = (char *)malloc(50);
strcpy(s1, "Prep");
strcpy(s2, "Insta");
strcat(s1, s2);
printf("%s", s1);
return 0;
}

Prep

Prep

Insta

Insta

Prep Insta

Prep Insta

PrepInsta

PrepInsta

(null)

(null)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]

Hey ! Follow us on G+