Computer Knowledge

Programming Fundamentals

2,381 Questions

Programming fundamentals form the core logic of software development and computer science. This includes variable declarations, pointer assignments, loop iterations, and exception handling. These technical topics are regularly tested in computer knowledge and IT officer competitive examinations.

Variables and arraysPointer assignmentsLoop iterationsException handling blocksCompile time errorsFunction references

Programming Fundamentals Questions

Multiple choice
  1. Only a

  2. Both a and b

  3. All a, b and c

  4. Both b and c

  5. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The program code is not simple if it contains loops, decision making statements and recursion. Option 3 is the correct answer.

Multiple choice
  1. Sets the precision

  2. Sets the initial or basic value of variable

  3. Converts the data of one number system to another

  4. No such manipulator present in C++

  5. Sets the base type like decimal, binary, hexadecimal

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

It is conversion manipulator that converts data of one number system to another.e.g.int x=15;cout<.

Multiple choice
  1. Virtual functions<o:p></o:p>

  2. templates<o:p></o:p>

  3. Namespaces<o:p></o:p>

  4. Inline function<o:p></o:p>

  5. None of above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Namespaces (user defined) are used for distinctly separating the scopes of the declarations and definitions in a program where the name clashes are likely to occur.

Multiple choice
  1. Only (1)

  2. Only (2)

  3. Only (3)

  4. Both (1) & (2)

  5. Both (2) & (3)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Function declaration no doubt specifies return type and parameters of function. So, statement (1) is correct. Variable declared in a function is unique. So, it cannot be used by another function. So, statement (2) is false. Rules of function allow us to declare as many functions in a program as we want. So, statement (3) is incorrect. Hence, only statement (2) is correct.

Multiple choice
  1. We put a semicolon in “while loop” after the while expression as in while(expression); , but semicolon is not allowed after while expression in “do while loop”.

  2. Difference between while loop and do while loop is the place where condition is tested.

  3. ”nested if“ statements cannot be used in while loop, but we can use “nested if” statements in do while loop.

  4. 'do while loop' causes the program to take more time to execute than while loop.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

We can use nested statements in both while loop and do while loop. So, option (3) is incorrect. While and do while loop take some time to execute the program. So, option (4) is also incorrect. We put a semicolon after while (expression) in do while loop, not in while loop. So, option (1) is also incorrect. In while loop, condition is checked following the while loop, but in do while loop, condition is checked at end of loop. Hence, option (4) is the correct answer.

Multiple choice
  1. Only (1)

  2. Only (2)

  3. Only (3)

  4. Both (1) & (2)

  5. Both (1) & (3)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The initialize counter of for loop sets the loop to initial value. For example: for (i =0; i<10; iH), loop initializes to zero. So, statement (1) is correct. The do while loop executes the body of loop at least once regardless of the logical condition. So, statement (2) is incorrect. The body of for loop does not require braces if there is only one statement after for loop. So, statement (3) is incorrect. Hence, option (1) is correct.

Multiple choice
  1. Only (1)

  2. Only (2)

  3. Only (3)

  4. Both (1) & (3)

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Variable name cannot start with a digit. So, statement (1) is incorrect. Variable cannot be a C keyword. So, statement (2) is incorrect. Spaces cannot be there while declaring variable. So, statement (3) is correct.

Multiple choice
  1. The variable name cannot start with a digit.

  2. The variables cannot be a C keyword.

  3. They must begin with a character without spaces but underscore is not permitted.

  4. Both 1 and 3.

  5. None of these

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Yes, this is true that variable name must start with a character. But we are allowed to put underscore. For example, Int ab_c; is a valid variable in C. So, this rule is not correct.

Multiple choice
  1. c=1

  2. c=0

  3. c=-1

  4. garbage value

  5. error in the program

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This program will first compare a > b, which is false as 9 < 10. So result will be 0. Then it will compare b > a (10 > 9) which is true. So result will be 1.So it will become as c=(0 || 1). So binary of 0 OR binary of 1. The result will be 1 0 0 0 0 0 1____0 0 1. So, this is the correct answer.

Multiple choice
  1. v=-1

  2. v=4294967295

  3. v=4294967296

  4. v=0

  5. error in the program

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Unsigned data types don’t have negative values. They have range from 0 to 4294967295. So, if negative value is given to any variable, it will count from its last value,  which is 4294967295. So, this is the correct answer. If we give v = -2, the result will be 4294967294. So, it will keep decrementing values.