top c questions by


									Here are some sample C sums for a successful job interviewing.

1. Arithmetic and Assignment Operators

  C++                                                      Purpose
  x++                                                      Postincrement
  ++x                                                      Preincrement
  x--                                                      Postdecrement
  --x                                                      Predecrement
  +x                                                       Unary plus
  -x                                                       Unary minus
  x*y                                                      Multiply
  x/y                                                      Divide
  x%y                                                      Modulus
  x+y                                                      Add
  x-y                                                      Subtract
  pow(x,y) or TMath::Power(x,y)                            Exponation
  x=y                                                      Assignment
  x += y (-=,*=,/=,%=,...)                                 Updating assignment

2. When we use void return type?

  We use it, when the method need not to return a value.
  A void return type indicates that a method does not return a value

3. What is an loop Statement?

  A Loop statement is one which execute a certain set of statement repeatedly until certain
  condition satisfied.

  For example::
  int i=0;
  cout << "hai";

  O/P:: hai

4. What do you mean by Swapping variables ?
   Swapping means the value of two or more variable is interchanging.

  For Example::

  int i=india;

  int j=china;

  int temp = i;

  i = j;

  j = temp;

  cout << i;

  Output:: china

6. What is a class?

  A class is a programming language construct that is used to group related instant variables and

7. What is an object?

  In OOP , an object is an instantiation (implementation) of a class.

8. What is the difference between an object and a class?

  A Class is constant one. All of the attributes of a class are fixed before, during, and after the
  execution of a program. The attributes of a class don't change

  Objects are created during execution and eventually destroyed. Also during that lifetime, the
  attributes of the object may undergo significant change.

9. Differnce between public and Private?

   Declaring a variable or member function private means that the variable & the function can be
   accessed only within the class or subclass.

   Declaring a variable or member function public means that the variable & the function can be
   accessed from any where in the code.

   Declaring a variable or member function private means that the variable & the function can be
   accessed only within the class or subclass.

10 Princeples of OOPS?
   The 4 principles of OOPS are Abstraction, Ineheritance, Polymorhpism and Encapsulation.
   Method Overloading and Overriding are a part of the Polymorphism

11 What is abstraction?

   Abstraction refers to the act of representing essential features without including the
   background details.

12 void main()
   int const * p=5;
   Compiler error: Cannot modify a constant value.
   p is a pointer to a "constant integer". But we tried to change the value of the "constant

13 main()
   char s[ ]="hai";
   int i;
   for(i=0;s[ i ];i++)
   printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
   s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array
   name is the base address for that array. Here s is the base address. i is the index
  number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may
  be surprising. But in the case of C it is same as s[i].

14 main()
   int i=-1,j=-1,k=0,l=2,m;
   printf("%d %d %d %d %d",i,j,k,l,m);
   Explanation :
   Logical operations always give a result of 1 or 0 . And also the logical AND (&&) operator
   has higher priority over the logical OR (||) operator. So the expression ‘i++ && j++ && k++’
   is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0). Now the expression
   is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’
   combination- for which it gives 0). So the value of m is 1. The values of other variables are
   also incremented by 1.

15 Difference between function overloading & 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 user-defined 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).

16 Diffrence between Realloc() and Free()?

  Realloc() is used to reallocate the memory for variable

  Free() is used to free the allocated memory of a variable

To top