Quiz of c programming language

Quiz of c programming language

Quiz of c programming language

Q 1 – What is the output of the following program?

#include<stdio.h>
main()
{
char*s =”Hello”;
while(*s!=NULL)
printf(“%c”,*s++);
}

A – Hello

B – Helloellolloloo

C – ello

D – Compile error 

Q 2 – What is the size of ‘int’?

A – 2

B – 4

C – 8

D – Compiler dependent

Q 3 – Choose the application option for the following program?

#include<stdio.h>
main()
{
int*p,**q;
printf(“%u\n”,sizeof(p));
printf(“%u\n”,sizeof(q));
}

A – Both the printf() will print the same value

B – First printf() prints the value less than the second.

C – Second printf() prints the value less than the first.

D – Error in the code.

Q 4 – Which of the following is used in mode string to open the file in binary mode?

A – a

B – b

C – B

D – bin

Q 5 – What is the output of the following program?

#include<stdio.h>
main()
{
char*s =”Fine”;
*s =’N’;
printf(“%s”, s);
}

A – Fine

B – Nine

C – Compile error

D – Runtime error

Q 6 – fgets() function is safer than gets() because in fgets() function you can specify the size of the buffer into which the supplied string will be stored.

A – True

B – False

Q 7 – What will be the output of the following program?

#include<stdio.h>
int main()
{
constint i =0;
printf(“%d\n”, i++);
return0;
}

A – 100

B – Infinity

C – 0

D – Return error

Q 8 – The library function strrchr() finds the first occurrence of a substring in another string.

A – Yes

B – Strstr()

C – strchr()

D – strnset()

Q 9 – What value strcmp() function returns when two strings are the same?

A – 0

B – 2

C – 1

D – Error

Q 10 – The library function strstr() finds the first occurrence of a substring in another string.

A – Yes

B – Strstr()

C – strchr()

D – strnset()

Answer with explaination

1)A

Explanation

NULL is equivalent to ‘\0’ in value. Statement *s++ prints the character first and increments the address later.

2)A

Explanation

Irrespective of any data type every type of pointer variable occupies same amount of memory.

3)A

Explanation

Irrespective of any data type every type of pointer variable occupies same amount of memory.

4)B

Explanation

To perform unformatted data I/O a file is opened in binary mode and is represented with the alphabet ‘b’ in the mode string.

5)B

Explanation

*s=’N’, changes the character at base address to ‘N’.

6)A

Explanation

Both functions retrive and store a string from console or file, but fgets() functions are more safer to use then gets() because gets() doesn’t facilitate to detail the length of the buffer to store the string in and fgets() facilitates to specify a maximum string length.

char*fgets(char*s,int size, FILE *stream);char*gets(char*s);

7)D

Explanation

It is because ++needs a value and a const variable can’t be modified.

#include<stdio.h> int main(){constint i =0; printf(“%d\n”, i++);return0;}

8)B

Explanation

Strstr() finds the first occurrence of a substring in another string.

9)A

Explaination

The C library function strcmp() compares two strings with each other and return the value accordingly.

intstrcmp(constchar*str1,constchar*str2)

Comparison happens between first string (str1) with second string (str2).

By comparing two strings, the values return by the function strcmp() are,

  • If, str1 is less than str2 then Return value < 0
  • Return value > 0 If, str2 is less than str1
  • If, str1 is equal to str2 then Return value = 0

10)B

Explanation

Strstr() finds the first occurrence of a substring in another string.

To get another quiz click here:

https://www.soluversity.in/quiz-6-c-programming-language

if you want know about programming language click here:google

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *