Wednesday, February 16, 2011

Find Output .


#include<stdio.h>
int main()
{
  char *s[] = { "knowledge","is","power"};
  char **p;
  p = s;
  printf("%s ", ++*p);
  printf("%s ", *p++);
  printf("%s ", ++*p);

  getchar();
  return 0;
}

Find Output .


#include<stdio.h>
int fun()
{
  static int num = 40;
  return num--;
}

int main()
{
  for(fun(); fun(); fun())
  {
    printf("%d ", fun());
  }
  getchar();
  return 0;
}

Declare a C/C++ function returning pointer to array of integer pointers..


Give definition for a function with argument of int* which returns pointer to an array of integer pointers.

Copy constructor and assignment operator.

#include<iostream>
#include<stdio.h>

using namespace std;

class Test
{
public:
   Test() {}
   Test(const Test &t)
   {
      cout<<"Copy constructor called "<<endl;
   }
   Test& operator = (const Test &t)
   {
      cout<<"Assignment operator called "<<endl;
   }
};

int main()
{
  Test t1, t2;
  t2 = t1;
  Test t3 = t1;
  getchar();
  return 0;
}


Output:
Assignment operator called
Copy constructor called
Copy constructor is called when a new object is created from an existing object, as a copy of the existing object. And assignment operator is called when an already initialized object is assigned a new value from another existing object.

t2 = t1;  // calls assignment operator, same as "t2.operator=(t1);"
Test t3 = t1;  // calls copy constructor, same as "Test t3(t1);"


Find the two non-repeating elements in an array of repeating elements


i.e Given an array in which all numbers except two are repeated once. (i.e. we have 2n+2 numbers and n numbers are occurring twice and remaining two have occurred once). Find those two numbers in the most efficient way.

Method 1(Use Sorting)
First sort all the elements. In the sorted array, by comparing adjacent elements we can easily get the non-repeating elements. Time complexity of this method is O(nLogn)

Find another method with more efficiency and very less complexity.

Compute the minimum or maximum of two integers without branching..

Do not use any conditions..  dont use ternary operators also..
just 1 line code.. :)

Predict the output of following C++ program.



#include <iostream>
using namespace std;
 
int main()
{
   int test = 0;
   cout << "First  character " << '1' << endl;
   cout << "Second character " << (test ? 3 : '1') << endl;
 
   return 0;
}

Multiply two integers without using multiplication, division and bitwise operators, and no loops

Write a Program..

How to swap two variables?

Question Looks Simple. But you have to done it by 1 line code only. no +/- or temp used.
write Maximal optimized code.

Hash key

The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function h(k) = k mod 10 and linear probing. What is the resultant hash table?

C++

In C++, what is the difference between exit(0) and return 0 ?
A max-heap is a heap where the value of each parent is greater than or equal to the values of its children. Which of the following is a max-heap?



Solve this Program and post code.


There are some unbiased coins (equal probability of having head and tail when tossed). Initially, all the coins are tossed. The following steps are followed after that:
- turn all the Head up coins to Tail.
- toss all the Tail up coins.
Find the probability of finding the a coin Head up after 'n' pairs of steps, ( or to frame it differently, find the number of coins with Head up) (Hint: think in terms of ratio)

Sunday, February 6, 2011

???

Where everyone yar??? now exams also completed...???????? should i post more questions or not???

Thursday, February 3, 2011

Pointers



What is the output of the program? '
#include<stdio.h>
#include<conio.h>
void main()
{
int **i;
int *j=0;
i=&j;
clrscr();
if(NULL != i && NULL != *i)
printf("hello”);
getch();
}

Thursday, January 27, 2011

Output / Error



The following code is written to get the multiplication and addition
of two given integer numbers. However, the multiplication of the
two numbers is correct but the addition of the two numbers is
incorrect. What is the output ? Identify the error.
#include<stdio .h>
#include<conio.h>
void main()
{
 int i=10, j=20;
clrscr();
multiply(&i, &j) ;
 addition(i , j) ;
getch() ;
}
multiply(int *1, int *j)
{
 *i=*i**j;
printf ("Multiplication of the two numbers is: : %d", *i);
}
addition(int i, int j)
{
i=i+j;
printf("\Addition of the two numbers is: : %d" , i) ;
}

Output..?


#include<stdio.h>  
#include<conio.h>
void main()
{
enum c{c·34, d-12, a, b};
clrscr():
if(a== (1==2))
printf("%d", a);
else
printf("%d" , b) ;
}

Tuesday, January 25, 2011

Questions - Answers

Hello All Now Any technical Questions Are Goings to posted here Weekly. Please Read Questions carefully and answer them within week.. i will post answer and explanation both after a time.. Please Do Reading Questions And answer them ... this is only For you.. If You all have any question and queries then post them also.. Thanks.