Computer Knowledge

Programming Fundamentals

2,611 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. 0

  2. 1

  3. -1

  4. None of the above

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

In C and C++, enumerated data types (enums) assign integer values starting from 0 by default. The first enumerator gets value 0, the next gets 1, and so on sequentially. However, programmers can explicitly assign different values if needed. This default behavior makes enums useful for array indexing and creating named constants.

Multiple choice
  1. True

  2. False

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

The arrow operator (->) is used in C/C++ to access members of a structure or class through a pointer. If ptr is a pointer to a structure, ptr->member is equivalent to (*ptr).member. This is a fundamental pointer operation for structured data.

Multiple choice
  1. stdlib.h

  2. process.h

  3. stdio.h

  4. dos.h

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

The fputs function writes a string to a file stream and is declared in stdio.h, which contains standard input/output functions. This header includes file operations like fputs, fgets, fprintf, and fscanf. stdlib.h is for general utilities, process.h for process control, and dos.h for DOS-specific functions.

Multiple choice
  1. dos.h

  2. stdlib.h

  3. alloc.h

  4. ctype.h

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

The isascii function checks if a character is an ASCII character (value 0-127) and is declared in ctype.h. This header contains character classification functions like isalpha, isdigit, islower, and isspace. alloc.h is for memory allocation, stdlib.h for general utilities, and dos.h for DOS-specific functions.

Multiple choice
  1. virtual

  2. assignment

  3. pointer

  4. object

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

In C++, 'virtual' is a reserved keyword used for polymorphism. Reserved keywords cannot be used as variable names, while 'assignment', 'pointer', and 'object' are valid identifiers.

Multiple choice
  1. applegrapesinvalid choice

  2. applegrapesinvalid choicebanana

  3. apple

  4. none of these

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

When input is 'a', case 'a' executes but has no break statement, causing fallthrough to case 'g' and then default. This outputs 'apple' + 'grapes' + 'invalid choice' without spaces.

Multiple choice
  1. extraction operator

  2. insertion operator

  3. get from operator

  4. put to operator

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

The << operator is called the 'put to' or insertion operator in C++ stream operations. It directs data to an output stream. Conversely, >> is the 'get from' or extraction operator.

Multiple choice
  1. for

  2. while

  3. do-while

  4. all of the above

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

The break statement immediately terminates the nearest enclosing loop or switch statement. It works with all loop types - for, while, and do-while - as well as switch statements, transferring control to the statement following the loop/switch.

Multiple choice
  1. float process( int i, float a, float b)

  2. double process(int i, double a, double b);

  3. double process (int i, float a, float b);

  4. long process(int i, float a, float b);

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

The function signature must match the specification: accepts an integer (int i), two floating point numbers (float a, float b), and returns a double precision quantity (double return type). Option C matches exactly: double process(int i, float a, float b). Note that option B is a declaration (semicolon) not a definition (no body).

Multiple choice
  1. compare three strings

  2. compare two strings

  3. copy strings

  4. compare and then copy strings

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

strcmp is a standard C library function that compares two strings lexicographically (character by character). It returns a negative value if the first string is less than the second, zero if they're equal, and positive if the first is greater. It cannot compare three strings at once, nor does it copy strings.

Multiple choice
  1. float *(15)[30];

  2. float [15][30];

  3. float *(x)[30];

  4. float *x[30];

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

The declaration 'float *(x)[30]' declares x as a pointer to an array of 30 floats. This is the correct syntax for declaring a pointer to a fixed-size 2D array where each row has exactly 30 float elements. The parentheses are crucial - they bind the pointer to the array, not to individual float elements.

Multiple choice
  1. p is a pointer to integer x

  2. both p and x are pointers to integer quantity

  3. px is an array of integer pointer

  4. px is a pointer to an integer quantity

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

The declaration 'int px' means px is a pointer variable that can hold the address of an integer quantity. The asterisk () indicates that px is a pointer, and 'int' specifies that it points to an integer type. Pointer variables store memory addresses, not the actual values.