0

C Programming Language Quiz 2

Description: C Programming Language Quiz 2
Number of Questions: 10
Created by:
Tags: c
Attempted 0/10 Correct 0 Score 0
c
  1. char s[] = { 'a', 'b' , 'c' };

  2. char s[] = "abc";

  3. both correct

  4. both wrong


Correct Option: C

What is the output of the following piece of code?

int x = 3, y = 5, z ;
z = x++ + ++y;

printf(ā€œ%dā€,z);

c
  1. 8

  2. 9

  3. 10

  4. 11


Correct Option: B
c
  1. Perform standard functions like printing to the screen

  2. Data storage

  3. Both correct

  4. Both wrong


Correct Option: B

what is the output of the following program

main(){
 int x;
 printf(ā€œ%dā€,x);
}

c
  1. Unknown (random value)

  2. Zero

  3. 3000

  4. 4000


Correct Option: A

float values(200) = ( 1 , 2 , 3 , 4 );

c
  1. is correct

  2. has syntax error

  3. causes run-time error

  4. none of the above


Correct Option: B

AI Explanation

To answer this question, let's analyze the given code:

float values(200) = ( 1 , 2 , 3 , 4 );

This line of code is attempting to declare and initialize an array called values of type float with a size of 200. However, there is a syntax error in this code.

The correct syntax for declaring and initializing an array in C++ is as follows:

float values[] = {1, 2, 3, 4};

In this case, the size of the array is automatically determined based on the number of elements provided in the initializer list.

Therefore, option B) has a syntax error is the correct answer.

Option A) is incorrect because the code has a syntax error. Option C) is incorrect because the code does not execute to cause a run-time error. Option D) is incorrect because the correct answer is B) has syntax error.

To write statement hi world:

c
  1. puts('hi world');

  2. puts("hi world");

  3. Both correct

  4. Both wrong


Correct Option: B
c
  1. Must be declared before being used.

  2. Can be used without declaration

  3. Can be used before declaration

  4. none of the above


Correct Option: A

consider the following statement:

while ( 3 ) ;

c
  1. Infinite loop

  2. Syntax error

  3. Executes only 3 iterations

  4. Executes only 4 iterations


Correct Option: A

To include a header file in a C program:

c
  1. #include "stdio.h"

  2. #include

  3. Both correct

  4. Both wrong


Correct Option: A

what is the best choice to print the value of variable x where:

int x = 123;

c
  1. printf("%f",x);

  2. printf("%d",x);

  3. printf("%c",x);

  4. printf("%s",x);


Correct Option: B
- Hide questions