0

Information Technology

Attempted 0/15 Correct 0 Score 0

Which is the actual syntax to find the ratio of boys and girls in C language? (given that float ratio; int boys, girls;)

  1. ratio = boys/girls;

  2. ratio = girls/boys;

  3. ratio = (float) girls/boys;

  4. ratio = (float) boys/girls;

  5. ratio = float boys/girls;


Correct Option: D
Explanation:

Cast operator is required to convert the boys/girls calculation in decimal precision. Cast operator can be used to explicitly convert the value of an expression to a different data type.

Find the output of the following code in C language assuming other parameters are correct. void main( ) { int a; int b; scanf ("%2d %5d", &a, &b); printf ("a = %d and b=%d.",a,b); }
/* input by the user is a=12345 and b = 67 during program execution*/

  1. a=12345 and b=67

  2. a=67 and b=12345

  3. a=12 and b=345

  4. a=12 and b=34567

  5. a=12 and b=67


Correct Option: C
Explanation:

%2d will restrict scanf function to assign only 2 digits in the variable a and rest of the digits will be assigned to the next scanf variable i.e. b.

Which one of the following is example of compound assignment operator in C language?

  1. a* = 5;

  2. a=a+5;

  3. a=a*5;

  4. a<5;

  5. a&&5


Correct Option: A
Explanation:

Actual calculation of this code is a=a*5; but to shorten the code and make the program execution faster compound operator is used. The compound assignment operators consist of a binary operator and the simple assignment operator. They perform the operation of the binary operator on both operands and store the result of that operation into the left operand, which must be a modifiable lvalue.

What will be output of the code if all other terms are assumed correct in C language? int age=17; (age>=18)? printf( I can vote.) : printf( I cannot vote.);

  1. Incorrect code

  2. Incorrect operator used

  3. I can vote

  4. I cannot vote

  5. No output


Correct Option: D
Explanation:

Age assigned with 17 hence,  the condition is not satisfied and second part is correct output.

'goto' statement is used in C programming to __________.

  1. jump the control to specific location o screen

  2. hold the control for user input

  3. end the program execution

  4. restart the execution from beginning

  5. jump the control up or down at its label


Correct Option: E
Explanation:

The goto statement is used to jump the control in a program to its label in the function irrespective of its place in the sequence of coding.

What is the right coding to find the formatted output of float value upto 4 decimal points? float a=23.76548;

  1. printf ( "% f ",a);

  2. printf ( "% 4" , a );

  3. printf ( "%2.4" f ;a);

  4. printf ( "% i" ,a);

  5. printf ( "%d" ;a);


Correct Option: C
Explanation:

This is the correct format of the output in which it will consider only four decimal points  after the number.

Which of the following is not correct in context to array in C language?

  1. It is a group of variables of similar datatype.

  2. It stores the data in consucative memory location.

  3. It is referred by a common name.

  4. int val[5].

  5. Array size can be changed during program execution.


Correct Option: E
Explanation:

Increasing or decreasing of array size is not possible during program execution. Array size must be decided during program coding.

Write the steps to interchange the variable values using least memory usages. Given that - int i, j;

  1. swap(i,j);

  2. i=j; j=i;

  3. i = i + j ;j = i - j ;i = i - j ;

  4. j = i - j;i = i + j ;i = i + j ;

  5. int temp;temp=i;i = j;j = temp;


Correct Option: C
Explanation:

These are  correct steps  used to interchange the values from one variable to other without using any other variable.

Which of the following statements is not correct about a function?

  1. It is a set of instructions.

  2. It performs a specific task.

  3. It is reusable.

  4. It is modular programming.

  5. None of these


Correct Option: E
Explanation:

All above are actual properties of a function.

Find the output of the following code in C language, if assumed that all preprocessor directives are correct. void main ( ) { int a = 2, b = 2; if (a > 2)
if (b > 2)
printf ( "Hello"); Else
Printf ("Hi"); }

  1. Hello

  2. Hi

  3. Error in execution

  4. Normal program execution without any output

  5. Program code error


Correct Option: D
Explanation:

First IF statement is not satisfied  hence,  control will  go to second if,  as it is a statment for first IF and ELSE statement will take priority for second IF which is jumped by control.  Hence,  no output will be coming in print however program will run normally.

If class name is Y, which is the right code to declare the copy constructor of the class?

  1. Y(const Y & arg )

  2. Y(Const *Y arg )

  3. Y(Y arg)

  4. Y(Y & arg)

  5. None of these


Correct Option: A
Explanation:

Copy constructor takes const as reference to the class type to the argument .

A user defined header file myheader.h is saved at root directory. Write pre-processor directives to include the header file in the program code in C language.

  1. include <myheader.h>

  2. include <myheader.h>

  3. include C:myheader.h

  4. include "C:myheader.h"

  5. main (C:myheader.h)


Correct Option: D
Explanation:

This the correct way to include the user defined header files in a program code. Here the header file is saved at root directory (C:).

Which of the following is true?

  1. define P printf

  2. define P printf

  3. use P printf

  4. include


Correct Option: A
Explanation:

This is used to define a different name of functions and this is the correct coding.

Which is correct statement about recursion?

  1. It is a function which calls to itself.

  2. It is a process in which a function calls to itself.

  3. It runs for definite number of time without condition.

  4. It is used to call global function.

  5. It is used to call local function.


Correct Option: B
Explanation:

This is the correct option as recursion is a process in which a function calls to itself. It is commonly used to calculate factorials.

Given code is written in C language. Find the output of the program.

int i = 6, j = 14, k = 7, l = 7, x; x = i > j ? j > k ? 12 : k > l? 13 : 14 : 15;printf("%d", x);

  1. 12

  2. 13

  3. 14

  4. 15

  5. %d


Correct Option: D
Explanation:

x = i > j ? j > k ? 12 : k > l? 13 : 14 : 15; Taking operator precedence, control will start executing from center of the statement. Step I:x = i > j ?( j > k ? 12 : k) > l? 13 : 14 : 15 // Control will get k from here  Step II: Remove the executed part for better understanding x = i > j ? ( k > l? 13 : 14) : 15  // Here value is 14 Step III: x = i > j ? 14 : 15 // i is not greater than j. Hence, 15 will be assigned in int x variable. 

- Hide questions