C Programming Language Quiz  1
Description: C Programming Language Quiz  1  
Number of Questions: 10  
Created by: Aliensbrain Bot  
Tags: c 
if ( 16 = m ) printf("m is 16");

is correct

has syntax error

causes runtime error

none of the above
To understand the answer to this question, the user needs to have knowledge of basic programming concepts, specifically the syntax and rules of the programming language being used. In this case, it appears to be a C programming language snippet.
Now, let's go through each option and explain why it is right or wrong:
A. is correct: This option is incorrect because the statement 16 = m
is using the assignment operator (=) in reverse. In C programming, the assignment operator is used to assign a value to a variable, not to compare values. The correct way to compare values in C is to use the equality operator (==). Therefore, the statement should be written as if (16 == m) printf("m is 16");
.
B. has syntax error: This option is correct. The given statement 16 = m
has a syntax error because it is using the assignment operator (=) in reverse, which is not allowed in C programming. The correct way to compare values in C is to use the equality operator (==). Therefore, the correct syntax should be if (16 == m) printf("m is 16");
.
C. causes runtime error: This option is incorrect because the given code does not have a runtime error. It has a syntax error, as mentioned in option B, but it will not cause a runtime error because it will not compile successfully.
D. none of the above: This option is incorrect because option B is correct. The given code has a syntax error and will not compile successfully.
Therefore, the correct answer is:
The Answer is: B. has syntax error
To copy a string into another, given:
char s1[30] = "xyz", s2[20];

s2 = s1;

strcpy(s2,s1);

s2 == s1;

all three are wrong
AI Explanation
To copy a string into another, you can use the strcpy()
function from the string.h library in C.
Let's go through each option to understand why it is correct or incorrect:
Option A) s2 = s1;  This option is incorrect because it assigns the memory address of s1
to s2
, rather than copying the contents of s1
into s2
.
Option B) strcpy(s2, s1);  This option is correct. The strcpy()
function is used to copy the contents of one string (s1
) into another string (s2
). It takes two arguments: the destination string (s2
) and the source string (s1
).
Option C) s2 == s1;  This option is incorrect. The ==
operator is used to compare the memory addresses of two variables, not their contents.
Option D) all three are wrong  This option is incorrect because option B is correct.
Therefore, the correct answer is B) strcpy(s2, s1);. This option correctly copies the contents of s1
into s2
using the strcpy()
function.
If LSB of a binary number is "0" then it is:

Positive number

Even number

Odd number

Prime number
AI Explanation
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) Positive number  This option is correct. The least significant bit (LSB) of a binary number represents the rightmost bit or the bit in the ones place. If the LSB is "0", it means that the number is divisible by 2 and therefore an even number. However, since the question specifically mentions that the number is positive, we can conclude that it is a positive even number.
Option B) Even number  This option is incorrect. While it is true that a binary number with a "0" LSB is an even number, the question asks specifically for a positive number, not just any even number.
Option C) Odd number  This option is incorrect. Since the LSB is "0", it means that the number is divisible by 2 and therefore an even number. It cannot be an odd number.
Option D) Prime number  This option is incorrect. The question does not provide any information about the primality of the number. The LSB being "0" does not provide any information about whether the number is prime or not.
The correct answer is A) Positive number. This option is correct because if the LSB of a binary number is "0", it means that the number is an even number, and since it is specified to be positive, it is a positive even number.
consider the following statement:
while ( 1 ) ;

Infinite loop

Syntax error

Depends on the compiler

none of the above
To understand the given statement and determine the correct answer, we need to analyze the syntax and behavior of the code.
The given statement is a while loop with the condition "1". In C and C++ programming languages, any nonzero value is considered true, and the loop will continue executing as long as the condition is true.
Let's go through each option and explain why it is right or wrong:
A. Infinite loop: This option is correct. Since the condition "1" is always true, the loop will continue executing indefinitely, resulting in an infinite loop. The loop will not terminate unless there is a break statement or the program is interrupted externally.
B. Syntax error: This option is incorrect. The given statement does not contain any syntax errors. It is a valid while loop syntax in C and C++.
C. Depends on the compiler: This option is incorrect. The behavior of the given statement does not depend on the compiler. The program will behave in the same way regardless of the compiler being used.
D. none of the above: This option is incorrect. As explained above, the correct answer is A, as the given statement will result in an infinite loop.
The Answer is: A
What is the output of the following piece of code?
int x = 3, y = 5, z;
z = x + ++y;
printf(“%d”,z);

8

9

10

11
AI Explanation
To determine the output of the given code, let's go through each line of code step by step:
int x = 3, y = 5, z;
 Here, three variablesx
,y
, andz
are declared and assigned the initial values of 3, 5, and garbage value respectively.z = x + ++y;
 In this line, the value ofy
is incremented by 1 (++y
) and then added to the value ofx
. So,y
becomes 6 andx + y
is 3 + 6 = 9. The result is stored in the variablez
.printf("%d", z);
 This line prints the value ofz
using the%d
format specifier, which represents an integer.
Therefore, the output of the code will be 9
.
Now, let's go through the options to determine the correct answer:
Option A) 8  This option is incorrect because the output of the code is 9
, not 8
.
Option B) 9  This option is correct. The output of the code is indeed 9
.
Option C) 10  This option is incorrect because the output of the code is not 10
.
Option D) 11  This option is incorrect because the output of the code is not 11
.
Therefore, the correct answer is B) 9.
The highest digit in any number system equals:

Zero

Base  1

Base 1

none of the above
To solve this question, the user needs to have knowledge of number systems and the concept of place value.
The highest digit in any number system is determined by the base of that number system. The base represents the number of unique digits used in that system. For example, in the decimal number system (base 10), the unique digits are 09. Therefore, the highest digit in the decimal system is 9.
Now, let's go through each option and explain why it is right or wrong:
A. Zero: This option is incorrect. Zero is not considered a digit in any number system. It is used to represent the absence of a value, but it does not have a place value or contribute to the magnitude of a number.
B. Base  1: This option is correct. The highest digit in any number system is one less than the base of that system. For example, in the binary number system (base 2), the highest digit is 1. In the decimal system (base 10), the highest digit is 9.
C. Base 1: This option is incorrect. Base 1 does not exist as a number system. A number system requires at least two unique digits to represent numbers. Base 1 would only have the digit 1, which is not enough to create a functional number system.
D. None of the above: This option is incorrect. As explained above, the highest digit in any number system is determined by the base of that system. Therefore, option D is not a valid response.
The Answer is: B. Base  1
The main() function is:

to write output to the screen

the program entry point

Both correct

Both wrong
To get a statement from the user input in the array char s[100]:

gets( s[100] );

gets( s[] );

gets( s );

none of the above
AI Explanation
To get a statement from the user input in the array char s[100]
, the correct option is C. gets( s );
Explanation:
A. gets( s[100] );
 This option is incorrect because s[100]
is accessing the 100th element of the array s
, which is not a valid argument for the gets()
function.
B. gets( s[] );
 This option is incorrect because s[]
is not a valid argument for the gets()
function. The []
should be followed by an index or a range of indices to specify which elements of the array to access.
C. gets( s );
 This option is correct because s
is the correct argument to pass to the gets()
function. It allows the user to input a string and store it in the array s
.
D. None of the above  This option is incorrect because option C, gets( s );
, is the correct option to get a statement from the user input in the array char s[100]
.
Therefore, the correct answer is C.
what is the output of the following program
int change( int x ) {
x = 7;
}
main(){
int x = 5;
change(x);
printf(“%d”,x);
}

5

7

9

unknown
AI Explanation
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) 5  This option is correct because the variable x
in the main
function is passed by value to the change
function. In the change
function, the value of x
is updated to 7, but this change does not affect the original x
variable in the main
function. Therefore, the value of x
in the main
function remains 5, and that is the value that is printed.
Option B) 7  This option is incorrect because the value of x
in the change
function is updated to 7, but this change does not affect the original x
variable in the main
function. Therefore, the value of x
in the main
function remains 5, not 7.
Option C) 9  This option is incorrect because nowhere in the program is there a statement that assigns the value 9 to the variable x
.
Option D) unknown  This option is incorrect because the behavior of the program is welldefined. The output will be a specific value, either 5 or 7, depending on the correct choice among the given options.
The correct answer is A) 5. This option is correct because, as explained earlier, the value of x
in the main
function remains 5, and that is the value that is printed.
Therefore, the correct answer is A) 5.
What is the output of the following piece of code:
int x = 7;
if ( x = 3 ) printf( “%d“ , x);

no output

7

3

5
To understand the output of this code, the user needs to know basic programming concepts, including variable assignment and the use of the if statement. The user must evaluate the code to determine the value of x and whether the if statement will execute its block of code.
Now, let's go through each option and explain why it is right or wrong:
A. no output: This option is incorrect. The code contains a printf statement, which will output the value of x if the if statement condition is true.
B. 7: This option is incorrect. The value of x is initially assigned the value 7, but this value is overwritten in the if statement condition.
C. 3: This option is correct. The if statement condition x = 3
is an assignment operation. It assigns the value 3 to x and also evaluates to 3. Since the value of x is now 3, the if statement condition is true, and the block of code will execute. The printf statement will output the value of x, which is 3.
D. 5: This option is incorrect. There is no mention of the value 5 in the code. The value assigned to x is 3, not 5.
Therefore, the correct answer is:
The Answer is: C. 3