Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

Q1. What is the output of this C code?

#include <stdio.h>
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf("%d %d\n", l, k);
return 0;
}
a) Compile time error
b) -1 1
c) 1 -1
d) Implementation defined
Answer b
Q2. What is the output of this C code?
#include <stdio.h>
void main()
{
int x = 1, y = 0, z = 5;
int a = x && y || z++;
printf("%d", z);
}
a) 6
b) 5

c) 0
d) Varies
Answer a
Q3.What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 1, y = 0, z = 3;
x > y ? printf("%d", z) : return z;
}
a) 3
b) 1
c) Compile time error
d) Run time error
answer c
Q4. What is the output of this C code?
#include <stdio.h>
void main()
{
int x = 1, z = 3;
int y = x << 3;
printf(" %d\n", y);
}
a) -2147483648
b) -1

c) Run time error


d) 8
answer d
Q5. What will be the value of d in the following program?
#include <stdio.h>
int main()
{
int a = 10, b = 5, c = 5;
int d;
d = b + c == a;
printf("%d", d);
}
a) Syntax error
b) 1
c) 5
d) 10
answer b
Q6. The output of the code below is
#include <stdio.h>
void main()
{
int x = 5;
if (x < 1)
printf("hello");
if (x == 5)

printf("hi");
else
printf("no");
}
a) hi
b) hello
c) no
d) None of the mentioned
answer a
Q7. Analyze the given code and state the output
#include <stdio.h>
int num = 10;
main()
{
int num = 20;
{
printf("\n %d", num);
}
printf(" %d", num);
}
a.10 20
b. 30 30
c. 20 10
d. None of above
Answer c

Q8. What is the output of given code


#include <stdio.h>
void display(struct stud);
struct student
{
int roll_no;
char name[100];
};
main()
{
struct student s;
s.roll_no = 10;
s.name = "ABC";
display(s);
}
display( struct student s1)
{
printf("\n %d %s", s.roll_no, s.name);
}
a)
b)
c)
d)

10 ABC
20 ABC
Abc 10
error

Answer-d
Structure must be displayed before the function

Q9. Analyze the given code and state the output


#include <stdio.h>
main()
{
int option = 1;
switch(option)
{
default: printf("Please check your option");
case 1: printf("\n SUM");
break;
case 2: printf("\n SUBTRACT");
break;
case 1*2+1: printf("\n MULTIPLY");
break;
}
}
a)sum
b)subtract
c)sumsum
d)multiply
Answer:d

Q10. What is the output of given code


main()

{
int arr[ ] = {1,2,3,4,5};
int i,*parr = arr;
for(i = 0;i < 5;i++) {
printf(" %d ",*arr);
++parr; }
}
a)
b)
c)
d)

00000
010101
11111
none

Answer: c
because parr is being incremented and we are printing the value of arr.
Q11. What is the output of given code
main()
{
int arr[ ] = {1,2,3,4,5};
int i,*parr = arr;
for(i = 0;i < 5;i++) {
printf(" %d ",*parr);
++parr; }
}
a)
b)
c)
d)
Ans: c

0111000
010101
12345
None of above

Q12. What is the output of given code


main()
{
int a =1,b = 1,c = 0, d = 2, res;
res = a++ && b++ && c++ || d++;
printf("%d %d %d %d %d", a, b, c, d, res);
}
a)
b)
c)
d)

0111000
00131
12345
None of above

Ans: b
Q13. What is the output of given code
main()
{
char *str;
printf("%d %d ",sizeof(*str), sizeof(str));
}
a)
b)
c)
d)

12
21
34
221

Answer: a
Since str is a pointer to a character type, its value needs 1 byte in memory and the address of this value will be
of 2 bytes.
Q14. What is the output of given code

main()
{
char str[]="Hello World";
show(str);
}
void show(char *str)
{
printf("%s",str);
}
a)
b)
c)
d)

Hello world
Hello World
HELLO WORLD
error

Ans:d ERROR. The default argument type and return type of a function is int. So a function that has any
other type of arguments and/or return type must be declared before it is called. In this case, the return type is
void and argument type is char and there is no declaration statement which gives the details to the compiler
in advance. Hence it is an error because the compiler assumes that the function will accept and return an
integer value.

Q15. What is the output of given code


main()
{
int num = 2;
printf("c=%d", 2);
}
a)
b)
c)
d)

--1
--2
%d%d
error

Ans: d ERROR. Unary operator can be applied to variables and not to constants. Since 2 is a
constant, therefore the program generates error.
Q16. What is the output of given code
#define int char
main()
{
int num = 65;
printf("%d",sizeof(num));
}
a)
b)
c)
d)

1
2
6
0

Ans: a
Because num is actually a char, not an int. See the #define statement

Q17. What is the output of given code


main()
{
int res=5;
res = !i > 6;
printf("res = %d", res);
}
a)
b)
c)
d)

Res=0
Res=1
Res=-1
None of above

Ans: a
Because res = 5 in line 1. In line 2, when we write !res, here ! is the negation operator which converts the value
of res to Zero. Now, 0 is not > Than 5.Therefore the value of res = 0.

Q18.What is the output of given code


main()
{
char str[] ={a,b,c,\n,c,\0};
char *p,*pstr;
p=&str[3];
printf("%d", *p);
pstr=str;
printf("%d", ++*pstr);
}
a)
b)
c)
d)

1089
1098
1000
1111

Ans: b
Because p is pointing to the third character in str which is \n. The ascii value of new line character is 10. pstr
stores the address of the first character in the str which is a. The value of *pstr is being incremented,
therefore it is 98. The ascii value of a + 1 = 97 +1 = 98
Q19. The first and second arguments of fopen are
a) A character string containing the name of the file & the second argument is the mode.
b) A character string containing the name of the user & the second argument is the mode.
c) A character string containing file poniter & the second argument is the mode.
d) None of the mentioned of the mentioned

Answer:a
Q20.For binary files, a ___ must be appended to the mode string.
a) Nothing
b) b
c) binary
d) 01
Answer B
Q21If there is any error while opening a file, fopen will return
a) Nothing
b) EOF
c) NULL
d) Depends on compiler
Answer C

Q22.Which is true about getc.getc returns?


a) The next character from the stream referred to by file pointer
b) EOF for end of file or error
c) Both a & b
d) Nothing.
Answer C
Q23.When a C program is started, O.S environment is responsible for opening file and providing pointer for
that file?
a) Standard input
b) Standard output
c) Standard error
d) All of the menitoned
Answer:d
Q24. FILE is of type ______ ?
a) int type
b) char * type
c) struct type
d) None of the mentioned
Answer:c

Q25. What is the meant by a in the following operation?


fp = fopen(Random.txt, a);
a) Attach
b) Append
c) Apprehend
d) Add
Answer:b
Q26. Which of the following mode argument is used to truncate?
a) a
b) f
c) w
d) t
Answer:c
Q27.Which type of files cant be opened using fopen()?
a) .txt
b) .bin
c) .c
d) None of the mentioned
Answer:d
Q28.What is the output for given code
main()
{
int arr[2][2][2] = { {1,3,5,7}, {2,4,6,8} };
int *p,*q;
p=&arr[2][2][2];
*q = ***a;
printf("%d %d",*p,*q);
}
a) Garbage Value 1
b) 2
c) Abcd

d) None
Answer a
Although arr is declared as a 3-D array, the third dimension is not initialized. Therefore, *p
will contain garbage value as no value exists for arr[2][2][2]. *q contains the address of the fi rst
element in the array, that is 1 in this case.

Q29. Why should one use standard library functions instead of writing new one?
The standard library functions have three advantages: they work, they're efficient, and they're portable.
They work: Your compiler vendor probably got them right. More important, the vendor is likely to have done
a thorough test to prove they're right, more thorough than you probably have time for. (There are expensive
test suites to make that job easier.)
They're efficient: Good C programmers use the standard library functions a lot, and good compiler vendors
know that. There's a competitive advantage for the vendor to provide a good implementation. When
competing compilers are compared for efficiency, a good compiler implementation can make all the
difference. The vendor has more motivation than you do, and probably more time, to produce a fast
implementation.
They're portable: In a world where software requirements change hourly, the standard library functions do
the same thing, and mean the same thing, for every compiler, on every computer. They're one of the few
things you, as a C programmer, can count on.
The funny thing is, one of the most standard pieces of information about the standard library is hard to find.
For every function, there's one header file (or, rarely, two) that guarantees to give you that function's

prototype. (You should always include the prototype for every function you call;) What's funny? That header
file might not be the file that actually contains the prototype. In some (sad!) cases, it's not even the header file
recommended by the compiler manual. The same is true for macros, typedefs, and global variables.
Q30. What is the difference between realloc() and free()?
The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results
occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will
occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to
the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer
specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and
not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is
not a valid pointer.
Q31. What is function overloading and operator overloading?
Function overloading: C++ enables several functions of the same name to be defined, as long as these
functions have different sets of parameters (at least as far as their types are concerned). This capability is
called function overloading. When an overloaded function is called, the C++ compiler selects the proper
function by examining the number, types and order of the arguments in the call. Function overloading is
commonly used to create several functions of the same name that perform similar tasks but on different data
types.
Operator overloading allows existing C++ operators to be redefined so that they work on objects of userdefined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant
facade that doesn't add anything fundamental to the language (but they can improve understandability and
reduce maintenance costs).
Q32. What is the difference between declaration and definition?
The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
E.g.: void stars () //function declaration
The definition contains the actual implementation.
E.g.: void stars () // declarator
{
for(int j=10; j > =0; j--) //function body
cout << *;
cout << endl; }
Q33. What are the advantages of inheritance?

It permits code reusability. Reusability saves time in program development. It encourages the reuse of proven
and debugged high-quality software, thus reducing problem after a system becomes functional.
Q34. What do you mean by inline function?
The idea behind inline functions is to insert the code of a called function at the point where the function is
called. If done carefully, this can improve the application's performance in exchange for increased compile
time and possibly (but not always) an increase in the size of the generated binary executables.
Q35. Write a short code using C++ to print out all odd number from 1 to 100 using a for loop
for( unsigned int i = 1; i < = 100; i++ )
if( i & 0x00000001 )
cout << i << \",\";
Q36. What is public, protected, private?
Public, protected and private are three access specifier in C++.
Public data members and member functions are accessible outside the class.
Protected data members and member functions are only available to derived classes.
Private data members and member functions cant be accessed outside the class. However there is an
exception can be using friend classes.
Write a function that swaps the values of two integers, using int* as the argument type.
void swap(int* a, int*b) {
int t;
t = *a;
*a = *b;
*b = t;
}
Q37. What is virtual constructors/destructors?
Answer Virtual destructors:
If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a baseclass pointer to the object, the base-class destructor function (matching the pointer type) is called on the
object.
There is a simple solution to this problem declare a virtual base-class destructor.
This makes all derived-class destructors virtual even though they dont have the same name as the base-class
destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a baseclass pointer to a derived-class object, the destructor for the appropriate class is called. Virtual constructor:
Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error.
Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete
operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is

called on the object.


There is a simple solution to this problem declare a virtual base-class destructor. This makes all derivedclass destructors virtual even though they dont have the same name as the base-class destructor. Now, if the
object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a
derived-class object, the destructor for the appropriate class is called.
Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax
error.
Q38. What are the advantages of inheritance?
It permits code reusability.
Reusability saves time in program development.
It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system
becomes functional.
Q39. What is the difference between declaration and definition?
The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
E.g.: void stars () //function declaration
The definition contains the actual implementation.
E.g.: void stars () // declarator
{
for(int j=10; j>=0; j--) //function body
cout<<*;
cout<<endl; }
Q40. What is the difference between an ARRAY and a LIST?
Answer1
Array is collection of homogeneous elements.
List is collection of heterogeneous elements.
For Array memory allocated is static and continuous.
For List memory allocated is dynamic and Random.
Array: User need not have to keep in track of next memory allocation.
List: User has to keep in Track of next location where memory is allocated.
Answer2
Array uses direct access of stored members, list uses sequencial access for members.

//With Array you have direct access to memory position 5


Object x = a[5]; // x takes directly a reference to 5th element of array
//With the list you have to cross all previous nodes in order to get the 5th node:
list mylist;
list::iterator it;
for( it = list.begin() ; it != list.end() ; it++ )
{
if( i==5)
{
x = *it;
break;
}
i++;
}
Q41.Does c++ support multilevel and multiple inheritance?
Yes.
Q42.What is a template?
Templates allow to create generic functions that admit any data type as parameters and return value without
having to overload the function with all the possible data types. Until certain point they fulfill the
functionality of a macro. Its prototype is any of the two following ones:

template <class indetifier> function_declaration; template <typename indetifier> function_declaration;


The only difference between both prototypes is the use of keyword class or typename, its use is indistinct since
both expressions have exactly the same meaning and behave exactly the same way.
Q43.Define a constructor - What it is and how it might be called (2 methods).
Answer constructor is a member function of the class, with the name of the function being the same as the
class name. It also specifies how the object should be initialized.
Ways of calling constructor:
1) Implicitly: automatically by complier when an object is created.
2) Calling the constructors explicitly is possible, but it makes the code unverifiable.
Other method
class Point2D{
int x; int y;

public Point2D() : x(0) , y(0) {} //default (no argument) constructor


};
main(){
Point2D MyPoint; // Implicit Constructor call. In order to allocate memory on stack, the default constructor
is implicitly called.
Point2D * pPoint = new Point2D(); // Explicit Constructor call. In order to allocate memory on HEAP we call
the default constructor.
You have two pairs: new() and delete() and another pair : alloc() and free().
Q44. Explain differences between eg. new() and malloc()
Answer 1.) new and delete are preprocessors while malloc() and free() are functions. [we dont use
brackets will calling new or delete].
2.) no need of allocate the memory while using new but in malloc() we have to use sizeof().
3.) new will initlize the new memory to 0 but malloc() gives random value in the new alloted memory
location [better to use calloc()]
new() allocates continous space for the object instace
malloc() allocates distributed space.
new() is castless, meaning that allocates memory for this specific type,
malloc(), calloc() allocate space for void * that is cated to the specific class type pointer.
Q45. What is the difference between class and structure?
Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a
particular functionality. But C++ extended the structure to contain functions also. The major difference is
that all declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all the members inside the class are private.
Q46. Explain term POLIMORPHISM and give an example using eg. SHAPE object: If I have a base class
SHAPE, how would I define DRAW methods for two objects CIRCLE and SQUARE
Answer POLYMORPHISM : A phenomenon which enables an object to react differently to the same function
call.
in C++ it is attained by using a keyword virtual
class SHAPE{
public virtual Draw() = 0; //abstract class with a pure virtual method
};

class CIRCLE{
public int r;
public virtual Draw() { this->drawCircle(0,0,r); }
};
class SQURE
public int a;
public virtual Draw() { this->drawRectangular(0,0,a,a); }
};
Each object is driven down from SHAPE implementing Draw() function in its own way.
Q47. What is an object?
Object is a software bundle of variables and related methods. Objects have state and behavior.
Q48. How can you tell what shell you are running on UNIX system?
You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return
prompt if you are from the Bourne shell, and a 5 digit random numbers if you are from the Korn shell. You
could also do a ps -l and look for the shell with the highest PID.
Q49. What do you mean by inheritance?
Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes.
The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of
its own.
Q50. Describe PRIVATE, PROTECTED and PUBLIC the differences and give examples.
class Point2D{
int x; int y;
public int color;
protected bool pinned;
public Point2D() : x(0) , y(0) {} //default (no argument) constructor
};
Point2D MyPoint;
You cannot directly access private data members when they are declared (implicitly) private:

MyPoint.x = 5; // Compiler will issue a compile ERROR


//Nor yoy can see them:
int x_dim = MyPoint.x; // Compiler will issue a compile ERROR
On the other hand, you can assign and read the public data members:
MyPoint.color = 255; // no problem
int col = MyPoint.color; // no problem
With protected data members you can read them but not write them: MyPoint.pinned = true; // Compiler will
issue a compile ERROR
bool isPinned = MyPoint.pinned; // no problem
Q51. What is namespace?
Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say it
somehow, they serve to split the global scope in sub-scopes known as namespaces.
The form to use namespaces is:
namespace identifier { namespace-body }
Where identifier is any valid identifier and namespace-body is the set of classes, objects and functions that are
included within the namespace. For example:
namespace general { int a, b; } In this case, a and b are normal variables integrated within the general
namespace. In order to access to these variables from outside the namespace we have to use the scope
operator ::. For example, to access the previous variables we would have to put:
general::a general::b
The functionality of namespaces is specially useful in case that there is a possibility that a global object or
function can have the same name than another one, causing a redefinition error.
Q52. What is a COPY CONSTRUCTOR and when is it called?
A copy constructor is a method that accepts an object of the same class and copies its data members to the
object on the left part of assignment:
class Point2D{
int x; int y;
public int color;
protected bool pinned;
public Point2D() : x(0) , y(0) {} //default (no argument) constructor

public Point2D( const Point2D & ) ;


};
Point2D::Point2D( const Point2D & p )
{
this->x = p.x;
this->y = p.y;
this->color = p.color;
this->pinned = p.pinned;
}
main(){
Point2D MyPoint;
MyPoint.color = 345;
Point2D AnotherPoint = Point2D( MyPoint ); // now AnotherPoint has color = 345
FEW ADDITIONAL MCQ
Q53. Difference b/w structure and union is
a.) Structure contains similar data but union contains different
b) union contains similar data but structure contain similar data
(c)In structure memory is allocated to all the variables at the same time and they
all can co exist which is not the case in union in
which all variables share one single memory area
(d)No difference at all
ANS : C
Q54. The main advantage of union over structure is
a. Union allows efficient use of memory
b. Union is more user friendly than structure
c. coding of union is easier
d. None
ANS : a
Q55. Which keyword is used to declare a union
a. UNION
b.union
c.struct

d.All
ANS: b
Q56. Why do we use typedef?
a. To declare new name for existing data type
b.To create new integers
c. To create new characters
d. To create new array
ANS : a
Q57.The method of accessing the members of union and structure is
a)same
b)different
c.)wecant access the members of union
d)We cant access the members of structure
ANS : a
Q58. Bit field is
(a) A way to specify number of bits in structure/union
(b) A way to name new data types
(c)A way to create name of existing data types
(d)All of these
Ans : a
Q59. Bit field is used in
(a) Structure
(b) pointer
(C)Function
(d)None
Ans :a
Q60. Can typedef be used with structure?
a)Yes
b) No
(c ) No because it will be a run time error
(d ) No because it will be a compile time error
ANS : A

Q61. The difference between union and array is


(a) A union can contain different data but array cant
(b) To access members of union we need to have a union variable , array elements
can be directly accessed
(c) In union all members share same memory location , in array all elements do
not share same memory location
(d) all of the above
ans : d
Q62. Which one is correct declaration for a union book
(a) union book { .... } ;
(b) create union book {.... };
(c) design union book { ...};
(d) make union book { ....} ;
ANS : a
Q63. A structure element is made bitfield by using
(a) KEYWORD bitfield
(b) KEYWORD field
(c) dot operator
(d)single colon
ANS : D
Q64. #include<stdio.h>
int main()
{ unionabc
{ int y;
charch[2];
};
unionabc u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.y);
return 0;
}
i. 3,2,garbage value

ii . 3, garbage,garbage
iii. Garbage value three times
iv. 3,2,1
ANS : i
Q65. Which operator is used to access the elements of union using union variable
(i) &
(ii)dot
(iii) *
(iv)None
ans ii
Q66. Union is similar to structure according to which statement
(i) both use the keyword struct
(ii)both use the keyword union
(iii)both can contain different type of data
(iv)bothcant have pointers
ans : iii
Q67. A union is
(i) derived data type
(ii)fundamental data type
(iii) user defined data type
(iv) none
ans: iii
Q68. Which one of the following is not a user defined data type
(i) structure
(ii)union
(iii)array
(iv) All are user defined
ans : iii
Q69. Find the output of given code?
#include<stdio.h>
int main()
{ union A

{ int x;
float y; };
union A u;
u.x=300;
u.y=22.22;
printf("%f",u.y);
return 0;
}
(a) 300
(b) garbage value
(c)22.22
d. None
ans : C
Q70.What is the output of given code
#include<stdio.h>
int main()
{
union A
{ int x;
float y;
};
union A u;
u.x=300;
u.y=22.22;
printf("%f",u.x);
return 0;
}
(a) 300
(b) 0 or garbage value
(c)22.22
(d)None
ans: b
Q71.choose the incorrect statement
(i)pointer cannot be created for union
(ii)structure can be used with union

(iii)pointer can be created for structure variables


(iv)structure can be nested
ans: (i)
Q72.Choose the incorrect statement
(i)The elements of structur can be of different type
(ii)the element of union cannot be of different type
(iii) pointer to a structure variable is possible
(iv)pointer to a union variable is possible
Ans: ii
Q73.Is it necessary that size of all elements in union must be same?
(i)yes
(ii)No
(iii)depends on compiler used
(iv)union has no elements
ANS : ii
Q74.Can we have array of bit fields in c ?
i.)yes
ii)No
(iii)yes but we will have to use stdlib.h
(iv) Yes but we will have to use math.h
ANS: ii
Q75.In a structure , we cannot create bit fields for
(i) int
(ii)signed int
(iii) unsigned int
(iv)float
ANS : D
Q76.Aself referential structure is
(i)a structure which is nested
(ii)a structure which has a union inside it
(iii)a structure which works like a union
(iv)a structure which points to itself

ANS: iv
Q77.Suppose we have two structures struct a and struct b . Read the code and
choose the correct option
struct A { int a;};
struct B(struct A ob1;
int b;};
struct B ob2;
(i)to access a we will have to write ob2.ob1.a;
(ii)to access a we will have to write ob1.a;
(iii)to access a we will have to write ob1.ob2.a;
(iv)None
ANS: i
Q78.Suppose we have two structures struct a and struct b . Read the code and
choose the correct option
struct A { int a;};
struct B(struct A ob1;
int b;};
struct B ob2;
(i)to access int b we will have to write ob2.ob1.b;
(ii)to access int b we will have to write ob2.b;
(iii)(iii)to access int b we will have to write ob1.b;
(iv)None
ANS: ii
Q79. The elements of a union by default belongs to
(i)auto storage class
(ii)register storage class
(iii)static storage class
(iv) none
ans (i)
Q80.The difference between typedef and #define is
(i) The typedefis limited to giving symbolic names to types only where as#define
can be used to define alias for values as well

(ii)typedef interpretation is done by compiler while #define is processed by


preprocessor
(iii) typedefcan not be used with structure but #define can be used
(iv) both i and ii
ans : iv
Q81. Read the following declaration
typedef unsigned char BYTE;
BYTE a,b;
in this program a and b will act as
(i) integers
(ii)floating point numbers
(iii)unsigned characters
(iv)unsigned integers
ANS : iii
Q82. Consider the following declaration in turbo C
structmystruct
{
unsignedint width : 1;
unsignedint height : 1;
} status;
now read the following statements
(i) width and heigh will be allotted 1 bit of memory each
(ii) width and height will be allotted 1 byte of memory each
(iii) status variable will be allotted 4 byte of memory
(iv) status variable will be 2 bit of memory
which statement is/are true
(a) only i
(b) only ii
(c) i and iii
(d) i and iv
ANS : C
Q83. Consider the following code
struct {
unsignedint a:3;

};
the maximum value that can be correctly stored in a is
(i)2 raised to the power 16
(ii) 2 raised to the power 15
(iii) 8
(iv) 7
ANS: iv
Q84. Consider the following code
struct {
int mynegativenumber:3;
};
the negative values which can be correctly stored in mynegativenumber are
(i)-4,-3,-2,-1
(ii) -3,-2,-1
(iii) negative infinity to -1
(iv) - 2 raised to the power 15 to -1
ANS: i
Q85. Read the following code (in turbo c)
struct student{
int a:3;
int b:2;
};
struct student s;
then the result of sizeof(s) will be
(i) 4
(ii)2
(iii)8
(iv)16
ans: ii
Q86.Find the output of given code
#include<stdio.h>
int main()
{t
ypedefintmyint;

myint a=5;
int b=4;
printf("%d",a==b);
return 0;
}
(i) 1
(ii)4
(iii)5
(iv)0
ans: IV
Q87. In turbo C (size of int =2 bytes) what will be the output of the following
#include<stdio.h>
int main()
{typedefintmyint;
myint a=5;
int b=4;
printf("%d",sizeof(a));
return 0;
}
(i)4
(ii)5
(iii)garbage value
(iv) 2
ANS: iv
Q88. What will be the output of the following
#include<stdio.h>
int main()
{t
ypedefintmyint;
typedef char mychar;
myint a=5;
mychar a='f';
printf("%d",sizeof(a));
return 0;
}

(i) 2 , because size of int is 2


(ii) 1 , because size of int is 4
(iii) ERROR , because of multiple declarations are conflicting
(iv)ERROR because size of cant be used with typedef variables
Ans : iii
Q88: What will be the output of the following in TURBO C
#include<stdio.h>
int main()
{
typedefint MYINT;
printf("%d",sizeof(MYINT) = =1);
return 0;
}
(i) 1
(ii)2
(iii)0
(iv)Lvalue required error
ANS: III
Q89Analyze the given code and tell the output
#include<stdio.h>
int main()
{t
ypedefint INT;
printf("%d",sizeof(INT)=5);
return 0;
}
(i) 0
(ii)1
(iii)5
(iv) Error: Lvalue required
ans: IV
Q90.Find the output of given code
#include<stdio.h>
int main(){

struct a{
int a;
};
struct a ob;
ob.a=5;
printf("%d",ob.a);
return 0;
}
(i) 5
(ii) 0
(iii) Error: structure name and variable name are same
(iv) garbage value
ANS: i
Q91. #include<stdio.h>
int main(){int a=6;
struct a{
int a;
};
struct a ob;
ob.a=5;
printf("%d",a);
return 0;
}
(i) 5
(ii) 6
(iii)garbage value
(iv) ERROR: because multiple declarations of a are conflicting
ans :ii
Q92. What will be the output of the following
#include<stdio.h>
int main( ){int a=6;
struct a{
int a;

};
union a{ int b;};
struct a ob;
union a ub;
ub.b=4;
ob.a=5;
printf("%d",a);
return 0;
}
(i) 4
(ii)5
(iii)6
(iv)Error : because of multiple declarations
Ans :iv

You might also like