CoCubes C Question and Answers Quiz-1

Question 1

Time: 00:00:00
Consider following given the code and predict its output.
main()
{
int num[ ] = {1,4,8,12,16};
int *a,*b; int i; a=num; b=num+2;
i=*a+1;
printf("%d,%d,%d\n",i,*a,*b);
}

2,1,8

2,1,8

4,1,8

4,1,8

4,4,8

4,4,8

2,4,8

2,4,8

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

Please login to submit your explanation

PrepInsta User

a=num[0] b=index of num[0]+2=8 i=address of num[0] +1=4 i=4 a=1 b=8

PrepInsta User

a=num[0] ; b=increment the index value i=*a+1

PrepInsta User

a=num[0] =1 b=num[0]+2=1+2=3 i=*a+1=pointer(1)+1=1+1=2 Therefore i=2 *a=pointer(1)=1 *b=pointer(3)=8

Question 2

Time: 00:00:00
What is stderr?

standard error

standard error

standard error types

standard error types

standard error streams

standard error streams

standard error definitions

standard error definitions

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

Please login to submit your explanation

PrepInsta User

The standard error stream is the default destination for error messages and other diagnostic warnings. Like stdout, it is usually also directed by default to the text console (generally, on the screen).

Question 3

Time: 00:00:00
What will be the output of the program for the input 'c'?

#include
int main()
{
int i;
char c;
for(i=1; i<=5; i++)
{
scanf("%c", &c);
printf("%c", c);
ungetc(c, stdin);
}
return 0;
}

cccc

cccc

c

c

ccccc

ccccc

Error in ungetc statement.

Error in ungetc statement.

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

Please login to submit your explanation

Question 4

Time: 00:00:00
What will be the output of the program?

#include
int main()
{
int i=-3, j=2, k=0, m;
m = i+(j++);
printf("%d, %d, %d, %d\n", i, j, k, m);
return 0;
}

 

2, 2, 0, 1

2, 2, 0, 1

1, 2, 1, 1

1, 2, 1, 1

-2, 2, 0, 0

-2, 2, 0, 0

-3, 3, 0,- 1

-3, 3, 0,- 1

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

Please login to submit your explanation

PrepInsta User

Since i is incremented, it becomes -2 j remians the same k remains 0 m is incremented thrice as ++i and becomes 0

Question 5

Time: 00:00:00
What will be the output of the program?
#include<stdio.h>
int main()
{
char ch;
ch = 'P';
printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'p' - 'P':ch);
return 0;
}

P

P

p

p

Error

Error

None of above

None of above

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

Please login to submit your explanation

Question 6

Time: 00:00:00
Point out the error in the program?

#include<stdio.h>
int main()
{
int a[] = {7657,7253,9242,5297,2958};
int j;
for(j=0; j<5; j++)
{
printf("%d\n", a);
a[j]++;
}
return 0;
}

 

Syntax error

Syntax error

Lvalue required

Lvalue required

No errors but prints garbage values

No errors but prints garbage values

Rvalue required

Rvalue required

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

Please login to submit your explanation

PrepInsta User

a++ is the short form of a = a + 1. However, a here is an array and you cannot modify the address of an array. So, the error is LValue required.

PrepInsta User

literals are RValue with with no address, so a++ operation need address thus we get LValue error

Question 7

Time: 00:00:00
#include<stdio.h>
void solve(int **p);

int main()
{
int arr[3][4] = {197, 22, 33, 44, 64, 43, 12, 87, 74, 88,39,90};
int *p;
p= &arr[0][0];
solve(&p);
return 0;
}
void solve(int **p)
{
printf("%d\n", **p);
}

197

197

88

88

43

43

22

22

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

Please login to submit your explanation

Question 8

Time: 00:00:00
Which among the following are declarations
1 : double solve(int);
2 : int fun(int A) { ... }
3 : extern int P;

1

1

2

2

3

3

1 & 3

1 & 3

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

Please login to submit your explanation

PrepInsta User

2 nd statement definition of function.

Question 9

Time: 00:00:00
Which function returns the first occurrence of a character within a string

strstr()

strstr()

strrchr()

strrchr()

strchr()

strchr()

strnset()

strnset()

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

Please login to submit your explanation

PrepInsta User

strstr(a,b) returns first occurrence of \'b\' string in \'a \' string. It returns index position.

Question 10

Time: 00:00:00
Which of the following statements are correct about an array?
1: ar[9] can store 9 elements
2: ar[2] gives you the second element of the array
3: you must initialize array at declaration of array

1,2

1,2

only 1

only 1

2,3

2,3

All 1,2,3

All 1,2,3

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

Please login to submit your explanation

PrepInsta User

num[SIZE] can be used as SIZE can be declared macro with constant value SIZE 50. in num[0] is the first element in array. int num[26] declaration of array where 26 specifies size.

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

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assistance

Get Access to PrepInsta Prime

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

Comments