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. A function cannot return more than 1 value.

  2. It is a group of statements that performs a task.

  3. Functions cannot be defined by the user.

  4. The return statement is used to return a value from a function.

  5. A function can call any number of functions.

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

Although most of the programs can be made using inbuilt functions like printf(), scanf(), the user has the option of declaring his own functions. Such functions are known as user defined functions. The main objective of a user defined function is to save time and effort since,  a method can be called as many times as required.

Multiple choice
  1. .(dot)

  2. * (Asterisk)

  3. & (Ampersand)

  4. -> (Arrow)

  5. # (Hash)

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

The -> (arrow) operator is used to reference individual members of a structures.The arrow operator is used with a pointer to an object. For example, if 'stud' is a pointer object pointing to a structure 'student', then the following statement can be used to access the member of the structure. printf("%d",*s->rollno);

Multiple choice
  1. We can have any number of case statements within a switch.

  2. When a break statement is reached, the switch terminates.

  3. Using default in switch case is optional.

  4. The value to be compared can be of any type.

  5. Every case need not have a break statement.

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

The value to be compared should be of integral type. We cannot compare a floating point value using a switch-case.

Multiple choice
  1. Structures are user defined data types.

  2. Structures cannot be nested.

  3. Structures can contain different types of variables.

  4. Structures are used to represent a record.

  5. The dot operator is used to access the structure members.

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

Structures can be nested. A structure can contain a reference of another structure. For example : struct person {   char name[10]:   int age; }; struct emp { int empno; personal person; }; In the above code the 'person' variable has a reference of the 'person' structure as its datatype. If an object of the structure 'emp' is declared, we can not only access the member of 'emp' but also of the 'person' structure.

Multiple choice
  1. sizeof

  2. !

  3. ~

  4. | |

  5. scope resoultion operator (: :)

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

The scope resoultion operator is not a valid C operator. It is used in C++ to specify the scope of a variable or object.

Multiple choice
  1. call by value

  2. call by name

  3. call by reference

  4. call by address

  5. call by default

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

The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. By default, C uses call by value to pass arguments. In general, this means that code within a function cannot alter the arguments used to call the function. 

Multiple choice
  1. continue can be used but break cannot be used

  2. continue cannot be used but break can be used

  3. Both continue and break can be used

  4. Neither continue nor break can be used

  5. We cannot use switch statement in nested form

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

The break is used to break out of the case statements. Break is a keyword that breaks out of the code block, usually surrounded by braces, which it is in. In this case, break prevents the program from falling through and executing the code in all the other case statements. 

Multiple choice
  1. always be evaluated

  2. be evaluated only if the definition is L-attributed

  3. be evaluated only if the definition has synthesized attributes

  4. never be evaluated

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

Every S (synthesized) -attributed definitions is L- attributed. So in a bottom-up evaluation of SDD inherited attributes can be evaluated only if the definition has synthesized attributes.

Multiple choice
  1. In statically typed languages, each variable in a program has a fixed type

  2. In un-typed languages, values do not have any types

  3. In dynamically typed languages, variables have no types

  4. In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program

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

(1) True for statically typed languages where each variable has fixed type. Similarly (4) is also correct. (2) True, in un-typed languages types of values are not defined. But option (3) is false, since in dynamically typed language variables have dynamically changing types but not that they have no type.

Multiple choice
  1. X = Y + Z

  2. t1 = Y + Z; X = t1

  3. t1 = Y; t2 = t1 + Z; X = t2

  4. t1 = Y; t2 = Z; t3 = t1 + t2; X = t3

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

In 3-address code we use temporary variables to reduce complex instructions so here $$ t_1 = Y \\ t_2 = Z \\ t_3 = t_1 + t_2 \\ x = t_3 \\ $$

Multiple choice
  1. always be evaluated

  2. be evaluated only if the definition is L-attributed

  3. be evaluated only if the definition has synthesized attributes

  4. never be evaluated

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

Every S (synthesized) -attributed definitions is L- attributed. So in a bottom-up evaluation of SDD inherited attributes can be evaluated only if the definition has synthesized attributes.

Multiple choice
  1. In statically typed languages, each variable in a program has a fixed type

  2. In un-typed languages, values do not have any types

  3. In dynamically typed languages, variables have no types

  4. In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program

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

(1) True for statically typed languages where each variable has fixed type. Similarly (4) is also correct. (2) True, in un-typed languages types of values are not defined. But option (3) is false, since in dynamically typed language variables have dynamically changing types but not that they have no type.

Multiple choice
  1. X = Y + Z

  2. t1 = Y + Z; X = t1

  3. t1 = Y; t2 = t1 + Z; X = t2

  4. t1 = Y; t2 = Z; t3 = t1 + t2; X = t3

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

In 3-address code we use temporary variables to reduce complex instructions so here $$ t_1 = Y \\ t_2 = Z \\ t_3 = t_1 + t_2 \\ x = t_3 \\ $$

Multiple choice
  1. 115, 220

  2. 25, 220

  3. 25, 15

  4. 115, 105

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

In static scoping the variables are initialized at compile time only So i =100 & j =5 P(i + j) = P(100 + 5) = P(105)

So x =105 x + 10 = 105 + 10 = 115 So 115 and 105 will be printed