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. 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. Fourth

  2. Fifth

  3. Third

  4. None of the above

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

Array elements are zero-indexed in C/C++ and most programming languages. Element myarray[4] is actually the fifth element because myarray[0] is the first, myarray[1] is the second, and so on. This zero-based indexing is a common source of off-by-one errors for beginners.

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. int digits[5]={1,2,3,4,5};

  2. float num[10];

  3. char color[3]={R,G,B};

  4. static float x[3]={2.5, 6.2, 7.8};

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

Character array elements must be character literals enclosed in single quotes. Option C uses 'R,G,B' without quotes, which is incorrect syntax - it would be interpreted as variables, not characters. The correct syntax would be char color[3]={'R','G','B'};

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.

Multiple choice
  1. as and when required

  2. at the end of the compilation process

  3. at the beginning of the compilation process

  4. while running the program

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

The C preprocessor processes directives (like #include, #define) at the beginning of compilation, before the actual compilation phase. This is why preprocessor directives can't use C syntax - they're processed by a separate program that prepares the source code for the compiler.