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. Local variables are declared inside a function and accessible within the function only.

  2. Global variables are declared in a separate file and accessible from any program.

  3. Global variables are declared inside a function and accessible from anywhere in the program.

  4. Local variables are declared in the main body only and accessible from functions only.

  5. Global variables are declared inside a function and accessible inside the function only.

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

Local variables are C program variables and hold scope inside a function only. Global variables hold scope for an entire program.

Multiple choice
  1. Line 7 should be like => int fun (int x, int y)

  2. At line 8 error: ‘x’ redeclared as different kind of symbol

  3. At line 10 error : return of local variable ‘x’

  4. No error

  5. None of the above

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

There is an error.At line 7 in fun (int x, int y) , one definition of x is already present and again we are defining it which throws re-declaration of 'x' error. So this is the correct answer.

Multiple choice
  1. Getchar() reads one character at a time till the user presses enter.

  2. Putchar() prints one character on the screen, which is read by the standard input.

  3. Getch() reads alphanumeric character from the input device.

  4. Getch() returns the character entered as input is not displayed by it.

  5. All of the above

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

All of the given options are correct.

Multiple choice
  1. Strspn();

  2. Strnset();

  3. Strnsetu();

  4. Strdup();

  5. Strncpy();

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

This option is true because this function takes two arguments and this function returns the position of the string from where the source array does not match with the target one. Format of this function is :-Strspn( string 1, string 2); For example suppose we enter first string as “good morning” and second string as “good luck”. So the function will return 5 because after 5 characters there is no match found in the strings. So this is the correct option.

Multiple choice
  1. Auto

  2. Register

  3. Static

  4. Extern

  5. Intern

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

The static storage class instructs the compiler to keep a local variable in existence during the lifetime of the program instead of creating and destroying it each time it comes into and goes out of scope. Therefore, making local variables static allows them to maintain their values between function calls.

Multiple choice
  1. By value

  2. By reference

  3. By name

  4. By passing all the values stored in the array

  5. The array cannot be used as a function argument

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

While passing arrays to the argument, the name of the array is passed as an argument, i.e, starting address of memory area is passed as argument. Hence, an array is passed by reference.

Multiple choice
  1. Auto

  2. Register

  3. Static

  4. Extern

  5. Intern

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

The static storage class instructs the compiler to keep a local variable in existence during the lifetime of the program instead of creating and destroying it each time it comes into and goes out of scope. Therefore, making local variables static allows them to maintain their values between function calls.

Multiple choice
  1. Thrown by pointer on allocation failure

  2. Thrown by new operator on allocation failure

  3. Thrown by wrong allocation of data type

  4. Thrown by cin and cout

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

When we are allocating the memory using new operator and allocation fail, then bad_alloc exception is thrown by the program.