DE Shaw :: Programming Questions - I
Posted by Subash | 10:45 AM
[9] Comments
Programming:-
- Swapping two variables x,y without using a temporary variable.
- Write a program for reversing the given string.
The integers from 1 to n are stored in an array in a random
fashion. but one integer is missing. write a program to find the
missing integer.
ans. idea. the sum of n natural numbers is = n(n+1)/2.
if we subtract the above sum from the sum of all the
numbers in the array , the result is nothing but the
missing number.- Write a c program to find whether a stack is progressing in forward or reverse direction.
- Write a c program that reverses the linked list.
typedef struct{
char *;
nodeptr next;
} * nodeptr;
what does nodeptr stand for?int *x[](); means
expl: Elments of an array can't be functions.o/p=?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
ans: 4#include
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye")}
main()
{
char *f();
printf("%c",*f()='A');
o/p=?FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)}
ans: no error. But It will over writes on same
file.#define MAN(x,y) (x)>(y)?(x):(y)
{ int i=10;j=5;k=0;
k= MAX(i++,++j)
printf(%d %d %d %d,i,j,k)}a=10;b=5; c=3;d=3;
if(awhat is o/p
> #include
> show(int t,va_list ptr1)
> {
> int a,x,i;
> a=va_arg(ptr1,int)
> printf("\n %d",a)
> }
> display(char)
> {int x;
> listptr;
> va_star(otr,s);
> n=va_arg(ptr,int);
> show(x,ptr);
> }
> main()
> {
> display("hello",4,12,13,14,44);
> }
> a) 13 b) 12 c) 44 d) 14main()
> {
> printf("hello");
> fork();
> }main()
> {
> int i = 10;
> printf(" %d %d %d \n", ++i, i++, ++i);
> }#include
> main()
> {
> int *p, *c, i;
> i = 5;
> p = (int*) (malloc(sizeof(i)));
> printf("\n%d",*p);
> *p = 10;
> printf("\n%d %d",i,*p);
> c = (int*) calloc(2);
> printf("\n%d\n",*c);
> }#define MAX(x,y) (x) >(y)?(x):(y)
> main()
> {
> int i=10,j=5,k=0;
> k= MAX(i++,++j);
> printf("%d..%d..%d",i,j,k);
> }#include
> main()
> {
> enum _tag{ left=10, right, front=100, back};
> printf("left is %d, right is %d, front is
> %d, back is
> %d",left,right,front,back);
> }main()
> {
> int a=10,b=20;
> a>=5?b=100:b=200;
> printf("%d\n",b);
> }#define PRINT(int) printf("int = %d ",int)
> main()
> {
> int x,y,z;
> x=03;y=02;z=01;
> PRINT(x^x);
> z<<=3;PRINT(x); > y>>=3;PRINT(y);
> }what is the o/p of the program
main()
{
int rows=3,colums=4;
int a[rows][colums]={1,2,3,4,5,6,7,8,9,10,11,12};
i=j=k=99;
for(i=0;iwhat is o/p
main()
{int i=3;
while(i--)
{
int i=100
i--;
printf("%d..",i);
}
}
a) infinite loop
b) error
c) 99..99..99..99
d) 3..22..1..
'-'=45 '/'=47
printfr(%d/n,'-','-','-','-','/','/','/');
o/p =?{ ch='A';
while(ch<='F'){ switch(ch){ case'A':case'B':case'C':case'D':ch++;continue; case'E':case'F':ch++; } putchar(ch); } } a)ABCDEF b.EFG c.FG d.error
1:30 AM
These are horrible questions. Who writes code like this?
6:26 PM
thanx for d effort
11:56 AM
In 3, looks like the correct answer is "undefined", not 4.
In operations like
int x = f() + g();
it is undefined whether f or g will be evaluated first.
7:50 PM
In 2 it is an array of function pointers i think............
7:52 PM
In 2 i think it is an array of function pointers.......
7:52 PM
In 2 i think it is an array of function pointers........
2:48 PM
hey friends..visit http://www.cracktheinterview.org for more interview questions and experiences
9:38 PM
Swap 2 variables without using a temp variable (I'm assuming the variable is an element of the real numbers):
a = 3;
b = 4;
if a == 0
a = b;
b = 0;
elseif b == 0
b = a;
a = 0;
else
a = a*b;
b = a/b;
a = a/b;
end
5:50 AM
Swap the two:
x = x + y
y = x - y
x = x - y