Computer Quiz: Basic Questions On C Language

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Millankmr
M
Millankmr
Community Contributor
Quizzes Created: 1 | Total Attempts: 925
Questions: 10 | Attempts: 925

SettingsSettingsSettings
Computer Quiz: Basic Questions On C Language - Quiz

.


Questions and Answers
  • 1. 

    What will be the output of the following program? #include<stdio.h> int main() { char numbers[5][6] = {"Zero","One","Two","Three","Four"}; printf("%s is %c",&numbers[4][0],numbers[0][0]); return 0; }

    • A.

      Four is Z

    • B.

      Three is Z

    • C.

      Compiler error

    • D.

      Two is Z

    Correct Answer
    A. Four is Z
    Explanation
    The program declares a 2D array of characters called "numbers" with 5 rows and 6 columns. It initializes the array with the strings "Zero", "One", "Two", "Three", and "Four".

    In the printf statement, it prints the character at the first index of the string in the 5th row of the array (which is 'F') and the character at the first index of the string in the 1st row of the array (which is 'Z').

    Therefore, the output of the program will be "Four is Z".

    Rate this question:

  • 2. 

    Which one of the following is an example of storage class in C?

    • A.

      Int and float

    • B.

      Extern

    • C.

      Both 1 & 2

    • D.

      Neither 1 nor 2

    Correct Answer
    B. Extern
    Explanation
    The correct answer is "extern" because it is a storage class in C. The "extern" keyword is used to declare a variable or function that is defined in another file or module. It is used to provide a reference to a global variable or function that is defined in a separate source file.

    Rate this question:

  • 3. 

    What will be the output of the following program? #include<stdio.h> int main() { int a = 1, b = 2, c = 3; printf("The value of a is %d", ++a); func(); printf(" The value of a is %d", ++a); return 0; } void func() { int a = 10; return 0; }

    • A.

      The value of a is 2 The value of a is 2

    • B.

      The value of a is 2 The value of a is 3

    • C.

      The value of a is 1 The value of a is 10

    • D.

      Compiler error

    Correct Answer
    B. The value of a is 2 The value of a is 3
    Explanation
    The output of the program will be "The value of a is 2 The value of a is 3". This is because the variable "a" is incremented twice using the pre-increment operator (++a) before each printf statement. The first printf statement is executed immediately after the increment, so it prints the value of "a" as 2. Then, the function func() is called, but it does not affect the value of "a". Finally, the second printf statement is executed, printing the value of "a" as 3.

    Rate this question:

  • 4. 

    What  is the output of the below program? #include<stdio.h> int main() { printf("%c", "abcdefgh"[6]); return 0; }

    • A.

      G

    • B.

      E

    • C.

      F

    • D.

      Compiler Error

    Correct Answer
    A. G
    Explanation
    The program uses array indexing to access the 6th character of the string "abcdefgh", which is 'g'. Therefore, the output of the program is 'g'.

    Rate this question:

  • 5. 

    What will be the output of the following program? #include<stdio.h> #define putchar(c) printf("%c",c) int  main() { char s='c'; putchar (s); return 0; }

    • A.

      99

    • B.

      Compiler Error

    • C.

      Runtime Error

    • D.

      C

    Correct Answer
    D. C
    Explanation
    The program includes the header file "stdio.h" and defines a macro "putchar(c)" which is equivalent to the printf statement "%c". In the main function, a character variable "s" is assigned the value 'c'. The putchar function is then called with the argument "s". Since putchar prints the character value passed to it, the output of the program will be the character 'c'.

    Rate this question:

  • 6. 

    What will be the output of the following program? #include<stdio.h> enum {TRUE, FALSE}; int main() { int i=1; do{ printf("%d\t",i); i++; if(i > 5) break; } while(TRUE); return 0; }

    • A.

      1 2 3 4 5

    • B.

      It prints an infinite loop of numbers

    • C.

      1 2 3 4

    • D.

      1

    Correct Answer
    D. 1
    Explanation
    The program uses a do-while loop to print the value of the variable "i" and then increments it. It checks if "i" is greater than 5 and if so, it breaks out of the loop. Since the condition for the loop to continue is "TRUE" and it is not changed within the loop, the loop will continue indefinitely. Therefore, the program will print an infinite loop of numbers starting from 1.

    Rate this question:

  • 7. 

    What will be the output of the following program ? #include<stdio.h> int main(){ typedef struct{char ch;}st; st s1 = {'c'}; st s2 = s1; if(s1 == s2) printf("Successful"); return 0; }

    • A.

      Successful

    • B.

      Compiler error

    • C.

      Compiler warning

    • D.

      None of these

    Correct Answer
    B. Compiler error
    Explanation
    The program will result in a compiler error. This is because the comparison operator "==" cannot be used to compare two struct variables.

    Rate this question:

  • 8. 

    What is the keyword used to turn off the compiler optimization of a variable?

    • A.

      Mutable

    • B.

      Volatile

    • C.

      Static

    • D.

      None of these

    Correct Answer
    B. Volatile
    Explanation
    The keyword "volatile" is used to turn off the compiler optimization of a variable. When a variable is declared as volatile, it indicates to the compiler that the value of the variable may change unexpectedly, and therefore the compiler should not optimize any code that involves that variable. This is useful in situations where the variable is accessed by multiple threads or in situations where the variable is modified by hardware or other external factors. By using the "volatile" keyword, the programmer ensures that the variable is always read from and written to memory, rather than being cached or optimized by the compiler.

    Rate this question:

  • 9. 

    What will be the output of the following program? #include<stdio.h> int main() { fun(); } fun() { printf("you are in fun"); main(); return 0; }

    • A.

      It will print "you are in fun" endlessly

    • B.

      Infinite loop

    • C.

      It is an example of tree recursion

    • D.

      Stack overflow

    Correct Answer
    D. Stack overflow
    Explanation
    The program will enter into an infinite loop because the function "fun" is calling the "main" function recursively without any termination condition. This will lead to the stack getting filled with function calls, eventually causing a stack overflow. As a result, the program will not be able to execute any further instructions and will terminate abruptly.

    Rate this question:

  • 10. 

    Which one of the following is the correct way of declaring main() function when it receives command line arguments?

    • A.

      Main(int argc, char argv)

    • B.

      Main(char argv[ ], int *argc)

    • C.

      Main(char* argv[ ],int argc)

    • D.

      Main(int argc,char* argv[ ])

    Correct Answer
    D. Main(int argc,char* argv[ ])
    Explanation
    The correct way of declaring the main() function when it receives command line arguments is "main(int argc,char* argv[ ])". This declaration specifies that the main() function takes two arguments - an integer "argc" which represents the number of command line arguments passed, and an array of character pointers "argv" which stores the actual command line arguments.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 18, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 02, 2013
    Quiz Created by
    Millankmr
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.