Showing posts with label easy. Show all posts
Showing posts with label easy. Show all posts

Saturday, December 3, 2011

Easy-4


void main()
{
int *mptr, *cptr;
mptr = (int*)malloc(sizeof(int));                               //Output: some garbage values
printf(“%d”,*mptr);
int *cptr = (int*)calloc(sizeof(int),1);                      // Output=0
printf(“%d”,*cptr);
}

The above statements return garbage values and a zero in the next.
So much for understanding a small difference between malloc() and calloc().
See the differences in arguments and the returned values.

Friday, December 2, 2011

A few simple logical questions !


1.) 

Multiplying a number by 7 without using * and + operators.

NewNum = Num << 3;                      // multiplied by 2^3 = 8

NewNum = NewNum - Num;             // 8 – 1 = 7

2.)

Finding the last character of any String.
                              (OR)

Write a function that finds the last instance of a character in a string


char *lastChar(char *String, char ch)
{
char *cStr = NULL;


// traverse the entire string


while(*String ++ != NULL ) 
{
if(*String==ch) 
cStr = String;
}
return cStr;


Saturday, November 26, 2011

Amazon easy simple output question


Another of internet giant Amazon's technical written test question. This question tries to make filter out candidates who have come to attend the examination after reading refreshers of C language. Delve into your K&R's to figure it out.

main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}

Hints:
\n - newline
\b - backspace
\r - linefeed
.
.
.
.
Solution coming soon !!