C Programming Online Quiz


Advertisements


Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - What is the output of the following code snippet?

#include<stdio.h>

main() 
{
    char c = 'A'+255;
   
    printf("%c", c);
}

A - A

B - B

C - Overflow error at runtime

D - Compile error

Answer : A

Explanation

A, the range of ASCII values for the ASCII characters is 0-255. Hence the addition operation circulates back to ‘A’

Q 2 - What is the output of the following program?

#include<stdio.h>

main()
{
   int x = 65, *p = &x;
   
   void *q=p;
   char *r=q;
   printf("%c",*r);
}

A - Garbage character.

B - A

C - 65

D - Compile error

Answer : B

Explanation

A, void pointer is a generic pointer and can hold any variable’s address. ASCII character for the value 65 is ‘A’

Q 3 - Identify the C compiler of UNIX.

A - gcc

B - cc

C - Borland

D - vc++

Answer : B

Explanation

‘cc’ full form is C Compiler and is the compiler for UNIX. gcc is GNU C compiler for linux. Borland and vc++ (Microsoft visual c++) for windows.

Q 4 - What is the output of the below code snippet.

#include<stdio.h>

main()
{
   printf("%d", -11%2);
}

A - 1

B - -1

C - 5.5

D - -5.5

Answer : B

Explanation

Modulus (%) operator is meant to give reminder for integer division.

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

#include<stdio.h>

void main()
{
   char s[] = "C++";
   
   printf("%s ",s);
   s++;
   printf("%s",s);
}

A - C++ C++

B - C++ ++

C - ++ ++

D - Compile error

Answer : D

Explanation

‘s’ refers to a constant address and cannot be incremented.

Q 6 - int fun(); - The declaration indicates the presence of a function defined inside the current module or in the same file.

A - True

B - False

Answer : A

Explanation

The function definition can even appear in another source code and can be linked from library while linking.

Q 7 - Which library function can convert an integer/long to a string?

A - ltoa()

B - ultoa()

C - sprintf()

D - None of the above

Answer : A

Explanation

In C, ltoa() function converts long/integer data type to string data type.

char *ltoa(long N, char *str, int base);

Q 8 - Which of the following statement can be used to free the allocated memory?

A - remove(var-name);

B - free(var-name);

C - vanish(var-name);

D - erase(var-name);

Answer : B

Explanation

The library function free() deallocates the memory allocated by calloc(), malloc(), or realloc().

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

A - 0

B - 2

C - 1

D - Error

Answer : A

Explanation

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

   int strcmp(const char *str1, const char *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
  • If, str2 is less than str1 then Return value > 0
  • If, str1 is equal to str2 then Return value = 0

Q 10 - extern int fun(); - The declaration indicates the presence of a global function defined outside the current module or in another file.

A - True

B - False

Answer : A

Explanation

Extern is used to resolve the scope of global identifier.


cprogramming_questions_answers.htm

Advertisements
E-Books Store