FREE! Click here to Join FunTrivia. Thousands of games, quizzes, and lots more!
Quiz about Beginning C Programming
Quiz about Beginning C Programming

Beginning C Programming Trivia Quiz


The C language has been around since 1972 and remains a favorite of programmers. It combines the convenience of a high-level language with the power of a low-level language. It is not without its oddities; some of which we will consider here.

A multiple-choice quiz by mike32768. Estimated time: 4 mins.
  1. Home
  2. »
  3. Quizzes
  4. »
  5. Science Trivia
  6. »
  7. Computers
  8. »
  9. Software and Programming

Author
mike32768
Time
4 mins
Type
Multiple Choice
Quiz #
253,015
Updated
Dec 03 21
# Qns
10
Difficulty
Average
Avg Score
7 / 10
Plays
3401
Last 3 plays: Guest 74 (9/10), samak (0/10), Triviaballer (10/10).
Question 1 of 10
1. Who are the writers of the classic manual, "The C Programming Language"? Hint


Question 2 of 10
2. In general (other than within string constants like "Hello World" and a few obscure constructs), what effect does the amount of whitespace (spaces and tabs) between code elements have on a C program's compiled output? Hint


Question 3 of 10
3. Why are line numbers used when writing C source code? Hint


Question 4 of 10
4. How does one indicate that certain text is to be treated as a "comment" in the classic C language? Hint


Question 5 of 10
5. What will this piece (snippet) of C code print to the screen?

printf("Hello World");
/* This is a comment
printf("Hello Again");
This is another comment */
Hint


Question 6 of 10
6. Is there a difference between i++ and ++i ? Hint


Question 7 of 10
7. Say you had a piece (snippet) of C code that looked like this:

if( i > 0 )
j = 5;

with both the if statement and the assignment on the same line. Now suppose that you insert a hard return (enter) right before "j=5;". What will change in the behavior of the code?
Hint


Question 8 of 10
8. In C programming, what does i equal at the end of the following piece (snippet) of code?

i = 1;
i *= 5;
i += 3;
Hint


Question 9 of 10
9. In the C language, how does one write the statement, "if i NOT equal to zero"? Hint


Question 10 of 10
10. When programming in C, what will j equal at the end of the following piece (snippet) of code?

i = 1;
j = 0;
if( i = 1 ) j = 3;
if( i = 2 ) j = 5;
Hint



(Optional) Create a Free FunTrivia ID to save the points you are about to earn:

arrow Select a User ID:
arrow Choose a Password:
arrow Your Email:




Most Recent Scores
Nov 13 2024 : Guest 74: 9/10
Nov 08 2024 : samak: 0/10
Oct 25 2024 : Triviaballer: 10/10
Oct 20 2024 : turtle52: 9/10
Oct 10 2024 : Guest 171: 8/10
Oct 05 2024 : Guest 178: 8/10
Sep 23 2024 : Guest 71: 9/10

Score Distribution

quiz
Quiz Answer Key and Fun Facts
1. Who are the writers of the classic manual, "The C Programming Language"?

Answer: Kernighan & Ritchie

Kernighan & Ritchie published the industry standard manual in 1978. It is still published and used today and is a staple in a serious C programmer's library.
2. In general (other than within string constants like "Hello World" and a few obscure constructs), what effect does the amount of whitespace (spaces and tabs) between code elements have on a C program's compiled output?

Answer: Spaces and tabs are both ignored.

Generally, whitespace (spaces, tabs, line feeds, returns) has no effect on the compiled code and beginning programmers should learn to use it liberally to make their code easier to read. As a player pointed out, the mere *presence* of whitespace can (but rarely) make a difference in some (rarely used) code constructs. For example:
i = a++ +b;
versus
i = a+ ++b;
3. Why are line numbers used when writing C source code?

Answer: They aren't used.

There are no line numbers used in writing C source code.

All "statement" lines end with a semicolon. Anything after the semicolon is really the start of the next line of code. So no numbers are needed to indicate a new line.

So this is legal:
i=3; j=5; k=i+j;

Line numbers ARE generally used by compilers to indicate locations of warnings or errors. The number, however, are NOT part of the C code proper.
4. How does one indicate that certain text is to be treated as a "comment" in the classic C language?

Answer: Place the text between /* */ .

Comments are text preceded by /* and ended with */

For example:
/* This is a comment
This is still a comment */

Even though it's not part of the pure (ANSI) C standard, most modern C compilers accept a double slash (//) at the start of a line to indicate that the rest of the line is a comment. Programmers have adopted this readily.

// This IS a comment
This is NOT a comment;
// This IS another comment
5. What will this piece (snippet) of C code print to the screen? printf("Hello World"); /* This is a comment printf("Hello Again"); This is another comment */

Answer: Only "Hello World".

The comment opening combination /* (slash, asterisk) starts a comment until the comment closing combination */ (asterisk, slash).

So everything between those two symbols are comments and not compiled - even if several lines are traversed.
6. Is there a difference between i++ and ++i ?

Answer: Sometimes there's a difference, sometimes not.

In the C language, the increment operator is ++ . The code i++ is the same as i = i + 1.

Further, i is incremented by one, regardless of which side the ++ operator is located. So, in most cases, the two constructs, i++ and ++i, are identical.

However, C allows you to construct some sophisticated code such as:
if( a > i++ )
in which case i is incremented AFTER its comparison with a.

Compare that to:
if( a > ++i ) ...
where i is incremented BEFORE the comparison.

It may seem elegant to take advantage of these types of subtle differences, but generally it's considered bad form to use constructs like either of these if statements as the original intention is likely not clear.
7. Say you had a piece (snippet) of C code that looked like this: if( i > 0 ) j = 5; with both the if statement and the assignment on the same line. Now suppose that you insert a hard return (enter) right before "j=5;". What will change in the behavior of the code?

Answer: Nothing, and both versions are legal.

They are the same - remember that white space doesn't matter in C.
8. In C programming, what does i equal at the end of the following piece (snippet) of code? i = 1; i *= 5; i += 3;

Answer: 8

The construct i *= 5 means the same as i = i * 5 (in other words, the new value of i equals the current value of i multiplied by 5).

Similarly, i += 3 means the same as i = i + 3.
9. In the C language, how does one write the statement, "if i NOT equal to zero"?

Answer: if ( i != 0 )

The exclamation point, ! , is the negative operator.
10. When programming in C, what will j equal at the end of the following piece (snippet) of code? i = 1; j = 0; if( i = 1 ) j = 3; if( i = 2 ) j = 5;

Answer: 5

A common error in C programming is forgetting that the statements
if( i = 1 ) and if( i == 1 ) are vastly different.

The code i = 1, even within the confines of an if statement, is an assignment, making i equal to one. That assignment occurs before the 'if' part is tested. Since i now equals one, the if evaluates as true, forcing the statement j=3 to be run. So now j=3. Likewise, the following if statement will do the same thing, running j=5. So, at the end, j equals 5!

More likely, the code should have been written as:
j = 0;
i = 1;
if( i == 1 ) j = 3;
if( i == 2 ) j = 5;

Then j would equal 3 at the end, as probably intended.
Source: Author mike32768

This quiz was reviewed by FunTrivia editor crisw before going online.
Any errors found in FunTrivia content are routinely corrected through our feedback system.
11/21/2024, Copyright 2024 FunTrivia, Inc. - Report an Error / Contact Us