Sail E0 Webinar

MCQs

Total Questions : 66 | Page 4 of 7 pages
Question 31.


What is the output of the program


#include<stdio.h>
int main ()
{
struct emp
{
char name [20] ;
int age;
float sal;
};
struct emp e = {"Tiger"};
printf ("%d, %f\n", e.age, e.sal);
return 0;
}
  1.    0, 0.000000
  2.    Garbage values
  3.    Error
  4.    None of above
 Discuss Question
Answer: Option A. -> 0, 0.000000

When an automatic structure is partially initialized remaining elements are

initialized to 0(zero).


Question 32.


What is the output of the program?


#include<stdio.h>
int main ()
{
extern int a;
printf ("%d\n", a);
}
int a = 20;
  1.    20
  2.    0
  3.    Garbage Value
  4.    Error
 Discuss Question
Answer: Option A. -> 20

extern int a; indicates that the variable a is defined elsewhere, usually in a 

separate source code module.

printf("%d`setminus`n", a); it prints the value of local variable int a = 20. Because, whenever 

there is a conflict between local variable and global variable, local variable gets the

 highest priority. So it prints 20.



Question 33.


What is the output of the program in Turbo C (in DOS 16-bit OS)?


#include<stdio.h>
int main()
{
char *s1;
char far *s2;
char huge *s3;
printf("%d, %d, %d\n", sizeof(s1), sizeof(s2), sizeof(s3));
return 0;
}
  1.    2, 4, 6
  2.    4, 4, 2
  3.    2, 4, 4
  4.    2, 2, 2
 Discuss Question
Answer: Option C. -> 2, 4, 4

Any pointer size is 2 bytes. (only 16-bit offset)
So, char *s1 = 2 bytes.
So, char far *s2; = 4 bytes.
So, char huge *s3; = 4 bytes.
A far, huge pointer has two parts: a 16-bit segment value and a 16-bit offset value.

Since C is a compiler dependent language, it may give different output in other platforms. 

The above program works fine in Window (TurboC), but error in Linux (GCC Compiler).



Question 34.


What will be the output of the program in 16 bit platform (Turbo C under DOS)?


#include<stdio.h>
int main()
{
extern int i;
i = 20;
printf ("%d\n", sizeof (i));
retutn 0;
}
  1.    2
  2.    4
  3.    vary from compiler
  4.    Linker Error : Undefined symbol 'i'
 Discuss Question
Answer: Option D. -> Linker Error : Undefined symbol 'i'

Linker Error : Undefined symbol 'i'

The statement extern int i specifies to the compiler that the memory for 'i' is allocated

 in some other program and that address will be given to the current program at the time

 of linking. But linker finds that no other variable of name 'i' is available in any other program 

with memory space allocated for it. Hence a linker error has occurred.


Question 35.


What is the output of the program given below ?


#include<stdio.h>
int main()
{
enum status { pass, fail, atkt};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2, = atkt;
stud3 = fail;
printf("%d, %d, %d\n", stud1, stud2, stud3);
}
  1.    0, 1, 2
  2.    0, 1, 2
  3.    0, 2, 1
  4.    1, 3, 2
 Discuss Question
Answer: Option C. -> 0, 2, 1

enum takes the format like {0,1,2..) so pass=0, fail=1, atkt=2

stud1 = pass (value is 0)

stud2 = atkt (value is 2)

stud3 = fail (value is 1)

Hence it prints 0, 2, 1


Question 36.

When we mention the prototype of a function?


  1.    Defining
  2.    Declaring
  3.    Prototyping
  4.    Calling
 Discuss Question
Answer: Option A. -> Defining

A function prototype in C or C++ is a declaration of a function that omits the function 

body but does specify the function's name, argument types and return type.

While a function definition specifies what a function does, a function prototype can be 

thought of as specifying its interface.


Question 37.

Identify which of the following are declarations

1: extern int x;

2: float square ( float x ) { ... }

3: double pow(double, double);


  1.    1
  2.    2
  3.    1 and 3
  4.    3
 Discuss Question
Answer: Option C. -> 1 and 3

extern int x; - is an external variable declaration.
double pow(double, double); - is a function prototype declaration.
Therefore, 1 and 3 are declarations. 2 is definition.


Question 38.

Is the following statement a declaration or definition?

extern int i;


  1.    Declaration
  2.    Definition
  3.    Function
  4.    Error
 Discuss Question
Answer: Option A. -> Declaration

Declaring is the way a programmer tells the compiler to expect a particular 

type, be it a variable, class/struct/union type, a function type (prototype) or 

a particular object instance. (ie. extern int i)

Declaration never reserves any space for the variable or instance in the

 program's memory; it simply a "hint" to the compiler that a use of the variable 

or instance is expected in the program.This hinting is technically called "forward 

reference".



Question 39.


In the following program where is the variable a getting defined and where it is
getting declared?


#include<stdio> .h>
int main()
{
extern int a;
printf("%d\n", a);
return 0;
}
int a = 20;
  1.    extern int a is declaration, int a = 20 is the definition
  2.    int a = 20 is declaration, extern int a is the definition
  3.    int a = 20 is definition, a is not defined
  4.    a is declared, a is not defined
 Discuss Question
Answer: Option A. -> extern int a is declaration, int a = 20 is the definition

- During declaration we tell the datatype of the Variable.

- During definition the value is initialized.



Question 40.


Which of the following is not user defined data type?
1:


struct book
{
char name[10];
float price;
int pages;
};
2:


long int 1 = 2.35;
3:


enum day {sun, mon, tue, wed};
  1.    1
  2.    2
  3.    3
  4.    Both 1 and 2
 Discuss Question
Answer: Option B. -> 2

C data types classification are

  1. Primary data types
    1. int
    2. char
    3. float
    4. double
    5. void
2. Secondary data types (or) User-defined data type
  1. Array
  2. Pointer
  3. Structure
  4. Union
  5. Enum
So, clearly long int l = 2.35; is not User-defined data type. 
(i.e.long int l = 2.35; is the answer.)


Latest Videos

Latest Test Papers