C String Questions 2

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 for the given code ?
#include <stdio.h>
char new[100];
char *loo(char str[])
{
static int i = 0;
if (*str)
{
loo(str+1);
new[i] = *str;
i++;
}
return new;
}

int main()
{
char str[] = "Best Site for placement";
printf("%s", loo(str));
return 0;
}

Best Site for placement

Best Site for placement

tnemecalp rof etiS tseB

tnemecalp rof etiS tseB

Segmentation core dump.

Segmentation core dump.

(null)

(null)

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 the correct output for the following program ?
#include<stdio.h>
void swap(char *arr1, char *arr2)
{
char *var = arr1;
arr1 = arr2;
arr2 = var;
}

int main()
{
char *arr1 = "Prep";
char *arr2 = "Insta";
swap(arr1, arr2);
printf("first string %s, second string is %s", arr1, arr2);
return 0;
}

first string Prep, second string is Insta

first string Prep, second string is Insta

first string Insta, second string is Prep

first string Insta, second string is Prep

fist string Prep, second string is Prep

fist string Prep, second string is Prep

fist string Insta, second string is Insta

fist string Insta, second string is Insta

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

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
Select the correct output of the Wollongong C code ?
#include<stdio.h>
int main()
{
char c[] = "ABCD1234";
char *p =c;
printf("%s", p + p[3] - p[1]) ;
}

ABCD234

ABCD234

1234

1234

CD1234

CD1234

ABCD

ABCD

34

34

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 following program ?
#include<stdio.h>
int main()
{
char arr[] = "PrepSter";
printf("%s %s %s ", &arr[5], &5[arr], arr+5);
printf("%c %c %c", *(arr+6), arr[6], 6[arr]);
return 0;
}

ter ter ter e e e

ter ter ter e e e

Ster ter ter t e e

Ster ter ter t e e

Ster Ster Ster e e e

Ster Ster Ster e e e

Compilation error.

Compilation error.

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 should be there in place of the blank so that Insta is printed ?
#include<stdio.h>
int main()
{
char str[] = "PrepInsta";
printf("%s", ______);
return 0;
}

str+3

str+3

str+4

str+4

str

str

Need to create an new array in order to print.

Need to create an new array in order to print.

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 we initialize a 3-D array with still space left for more values like in the code below.

#include<stdio.h>
int main()
{
char a[2][3][3] = {'p','r','e','p','i','n','s','t','a'};
printf("%s ", *a);
return 0;
}

What shall be printed in the end ?

pr followed by garbage values

pr followed by garbage values

prepinsta followed by garbage values

prepinsta followed by garbage values

prepinsta

prepinsta

Compilation error.

Compilation error.

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 expected output of the following program ?
#include <stdio.h>

int main()
{
char str[]="prepster";
int size;
size=strlen(str);
int i;
char p[size];
for(i=0;i<size;i++)
p[i]=str[size-i];
printf("%s",p);
}

prepster

prepster

retsperp

retsperp

etsperp

etsperp

(null)

(null)

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 shall be the correct output for the C code below ?
# include <stdio.h>
int main()
{
char str1[] = "PerpInsta";
char str2[] = {'P', 'r', 'e', 'p', 'I', 'n', 's', 't', 'a'};
int a = sizeof(str1)/sizeof(str1[0]);
int b = sizeof(str2)/sizeof(str2[0]);
printf("%d %d", a, b);
return 0;
}

9 9

9 9

10 10

10 10

9 8

9 8

10 9

10 9

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!"]