C Interview Questions
- 0of 0 votes
Answers`#include<stdio.h>
- ajaybhardwaj789 May 22, 2014 in India
int main(void)
{
int s[4][2] = { {1234,56}, {1212,33}, {1434,80}, {1312,78} };
int (*p)[2];
int i, j, *pint;
for( i=0; i<=3; i++)
{
p = &s[i];
pint = (int*)p; //Q. My Question is why we are required to type cast here. ?
printf("\n");
for( j=0; j<=1; j++)
{
printf("%d",*(pint+j));
}
}
return 0;
}`
Why we are required to perform the typecasting at the comment line ?
What is the exact difference between
1. Pointer to an array int (*ptr)[10]; and
2. Array of pointers int *ptr[10];| Report Duplicate | Flag | PURGE
CSC Software Engineer / Developer C - 1of 1 vote
AnswersWrite a function to return a path from a given node of a Binary tree to the node on its right.
- 14mit1010 May 10, 2014 in India
Each node contains a left pointer, a right pointer and a parent pointer
The root node is not provided, the tree is not balanced, the tree is not a Binary search tree
Finding the root node and running BFS from there is not an acceptable solution. You have 30 minutes to give syntactically correct code
I was unable to complete this question and was rejected without further interviews. Perhaps I did something to offend the interviewer, this was for an entry level SDE position| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C - 0of 0 votes
AnswersYou are given an array of N elements. Each element in the range Min of int to Max of Int. You need to find the length of longest sequence in this array such that difference of largest and smallest element of that sequence is 1. The sequence need not be sequential.
- northernlight May 06, 2014 in United Kingdom
For e.g. array[]={6,10,6,7,8,9,0}
seq {6,10} = diff is 4 len 2
seq { 10,7,8} diff is 3 len 3
seq { 7,8,9} diff 2 len 3
seq {6,6,7} diff is 1 len 3
In this example the program should return 3 .
Complexity N*longN| Report Duplicate | Flag | PURGE
Amazon Algorithm Arrays C C++ - 1of 3 votes
AnswersWrite a function in C to create a new BST which is the mirror image of a given tree.
- gjp February 24, 2014 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern Algorithm C Data Structures - 3of 7 votes
AnswersConsider the statement
- gjp February 24, 2014 in United States
result = a ? b : c;
Implement the above statement without using any conditional statements.| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern Bit Manipulation C - 0of 0 votes
AnswersWrite a multi threaded C code with one thread printing all even numbers and the other all odd numbers. The output should always be in sequence
- gjp February 24, 2014 in United States
ie. 0,1,2,3,4....etc| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern C Threads - 0of 0 votes
AnswersWrite a piece of code to find out if the system is x86 architecure of Sparc
- gjp February 24, 2014 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer Intern C Computer Architecture & Low Level - -1of 1 vote
AnswersExplain the output of the following code:
- gdg February 14, 2014 in United Statesint main( ) { int x = 10, y = 20;/. x =!x; y =!x&&!y; printf(“x =%d y =%d”, x, y); return 0; }
| Report Duplicate | Flag | PURGE
Amazon C - 1of 1 vote
AnswersWrite a piece of code to find out if the system is x86 architecure of Sparc
- gjp February 12, 2014 in United States| Report Duplicate | Flag | PURGE
Bit Manipulation C - 0of 2 votes
AnswersConsider 0 as water and 1 as land. Write code in C to find out whether there is pool in the following matrices.
- bks February 09, 2014 in India
11111
10001
10001
11111
above matrix is pool
11111
11001
11001
10111
11111
above matrix is NOT pool
11111
11001
11001
10001
11111
above matrix is pool
11111
11101
11001
10001
11111
above matrix is pool| Report Duplicate | Flag | PURGE
Amazon SDE-2 C - 9of 9 votes
AnswersWrite a program for finding a minimum element in rotated sorted array(either ascending or descending ) and array contains duplicates.
- kesar February 02, 2014 in United States| Report Duplicate | Flag | PURGE
Algorithm Arrays C Sorting C# - -1of 1 vote
AnswersBy mistake I wrote the following program and it compiles and runs without any error in gcc compiler. enter code here
- Amit January 28, 2014 in India
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,**data;
data=(int **)malloc(sizeof(int)*1000000);
for(i=0;i<1000000;i++)
data[i]=(int *)malloc(sizeof(int)*1000000);
printf("done\n");
return 0;
}
But I don't understand how is it allocating an array of 1000000*1000000 bytes,almost equivalent to 1TB??| Report Duplicate | Flag | PURGE
SDE1 C - 0of 0 votes
AnswersStruct node{
- renjumc January 28, 2014 in India
node *pNext;
node *pRandom;
};
You have a link list of the above node structure. pRandom has connection to any random nodes.
Write a program to clone this list.
note:You should not add any new items to node| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer C C# C++ - -2of 2 votes
AnswersWrite a program to find the GCD of two numbers
- renjumc January 28, 2014 in India| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer C C# C++ - 0of 0 votes
AnswersFirst find out the number 1's in the binary digit of a given integer. Then find out an integer which is greater than the given integer and contains same number of binary 1's
- Arunkumar V January 21, 2014 in India| Report Duplicate | Flag | PURGE
Software Engineer in Test C Coding - 0of 0 votes
AnswersWrite a function to check if two rectangles defined as below, have common area or not. The functions take the top left and
- chhatreshpatel January 17, 2014 in United States
bottom right coordinate as input and return 1 if they have common area, otherwise return 0.
// you can write your additional functions here
int doesRectOverlap(rect ra, rect rb){
/* For your reference
struct rect{
int topx,topy,botx,boty;
};
The above has already been declared please do not redclare */| Report Duplicate | Flag | PURGE
Amazon Applications Developer C - 3of 3 votes
AnswersThe interviewer asked the following question.
char *s = "Hello"; printf("%s",s); printf(s)
The second print statement crashes sometimes. Why
- chid1989 January 07, 2014 in United States| Report Duplicate | Flag | PURGE
NVIDIA Intern C - -2of 2 votes
AnswersThe way a Knight Given a chessboard, consisting of n×n cells, several of them are cut. Find the path of minimum length for a Knight from one cell to another. The Knight can’t go through cut cells.
- Eliana December 24, 2013 in United States for interviews
Specifications
Input
The first row is set to the number n (2 ≤ n ≤ 50). Each of the next n lines contains n symbols. The symbol # denotes the cut cell, the point - not cut cell, the symbol @ denotes the initial and final cell of the Knight's path (the chessboard contains two such characters).
Output If the path can not be constructed, print "Impossible". Otherwise display the same map as the input, but check all Knight intermediate positions with symbol @. Example
Example input
5
.....
.@@..
.....
.....
.....
5
@..@.
..##.
.....
.....
.....
5
@....
..#..
.#...
.....
....@
Example output
Sample 1
...@.
.@@..
....@
.....
.....
Sample 2
@..@.
..##.
.@..@
..@..
@....
Sample 3
Impossible| Report Duplicate | Flag | PURGE
Informatica iOS Developer C - 1of 1 vote
AnswersThe way a Knight
- Eliana December 12, 2013 in United States for games developing
Given a chessboard, consisting of n×n cells, several of them are cut. Find the path of minimum length for a Knight from one cell to another. The Knight can’t go through cut cells.
Specifications
Input
The first row is set to the number n (2 ≤ n ≤ 50). Each of the next n lines contains n symbols. The symbol # denotes the cut cell, the point - not cut cell, the symbol @ denotes the initial and final cell of the Knight's path (the chessboard contains two such characters).
Output If the path can not be constructed, print "Impossible". Otherwise display the same map as the input, but check all Knight intermediate positions with symbol @.
Example
Example input
5
.....
.@@..
.....
.....
.....
5
@..@.
..##.
.....
.....
.....
5
@....
..#..
.#...
.....
....@
Example output
Sample 1
...@.
.@@..
....@
.....
.....
Sample 2
@..@.
..##.
.@..@
..@..
@....
Sample 3
Impossible| Report Duplicate | Flag | PURGE
Akamai Computer Scientist C - 0of 2 votes
AnswersYou are given an array A[] of N integers. The array is unsorted, and N integers can take any value from -2,147,483,647 to + 2,147,483,647. You are supposed to find index Q of a pivot point such that, for 0 <= i <= Q, A[i] <= A[Q], and for Q <= j < N, A[Q] <= A[j].
- May A November 19, 2013 in United States
If no such pivot point exists, you should return -1.
The expected worst case time complexity is O(N), and expected worst case space complexity (in addition to array A) is O(N).| Report Duplicate | Flag | PURGE
Algorithm C - 0of 0 votes
AnswersWhats wrong in this code?
- vicky123 November 19, 2013 in India
#include<stdio.h>
#include<stdlib.h>
void mystrcpy( char *string2 ,char *string1 )
{
string2 = malloc(20);
while( *string1 != '\0')
{
*string2++= *string1++;
}
}
int main()
{
printf("****************program starts*************************");
char *str1 ="hello world";
char *str2 =NULL;
mystrcpy( str2,str1);
printf("string1 = %s string2 =%s ",str1,str2) ;
getche();
return 0;
}
why str2 will print NULL here| Report Duplicate | Flag | PURGE
Analyst C - 3of 3 votes
AnswersGiven two parameters (a target string and a source string), write code that returns the number of times characters found in the source string occur in the target string.
- ootah November 14, 2013 in United States
For example, if target="Hello world" and source="llld" then return 4| Report Duplicate | Flag | PURGE
Citrix System Inc Software Engineer / Developer C - -2of 2 votes
Answersdetermine the series of numbers entered (array a) from the encoded output of the program (array b).
- logkeyer October 18, 2013For i from 0 to size - 1: For j from 0 to size - 1: b[(i+j)/32] ^= ((a[i/32] >> (i%32)) & (a[j/32 + size/32] >> (j%32)) & 1) << ((i+j)%32)
| Report Duplicate | Flag | PURGE
Mathworks Graphics Programmer Algorithm C C# - -2of 2 votes
AnswersAdd the ODD ORDERED elements in a matrix.But the intersecting(middle) element must be added only once.
- Anonymous September 15, 2013 in India
Ex:
467
932
148
in this matrix 4,7,3,1,8 are odd indexed or odd ordered elements;We have to add them but,
###constraint ###
intersecting(middle) element must be added(used) only once.| Report Duplicate | Flag | PURGE
Amazon Applications Developer C - 1of 3 votes
AnswersReverse a string without using any temporary variable.
- rasmiranjanbabu August 31, 2013 in India
Suppose {{char str[] = "Hello"; then str[] = "olleH";}}}.
I told him we can "shift H to o then o to H", similarly so on. But could able to write the code.| Report Duplicate | Flag | PURGE
HCL Software Engineer / Developer C - 0of 0 votes
Answerswrite a program that prints numbers 1 to 100
- sudhakar810nit August 28, 2013 in United States
with most efficient condition
1. Run Time Complexity
2. Run time Space complexity
3. Compilation Time
4. Compile Time Space Complexity
5. Power complexity (reduction of battery used)| Report Duplicate | Flag | PURGE
Search Media C - 0of 2 votes
Answers#include<stdio.h> void main() { void *p; int x=10; float y=20.2; p=&x; printf("int %d\n",*p); *p=20; p=&y; printf("float %d\n",*p); }
What is the output?
- sharma7067 August 19, 2013 in India
If error, which error and correct the code.| Report Duplicate | Flag | PURGE
HCL Software Engineer / Developer C - 2of 2 votes
Answershow much memory can calloc and malloc can allocate???
- saran August 17, 2013 in India| Report Duplicate | Flag | PURGE
Samsung C - 1of 1 vote
AnswersHow answer is coming as zero instead of garbage? Does compiler sets "0" to uninitialized variable?
- rasmiranjanbabu August 15, 2013 in India#include<stdio.h> void fun(void *p); int i; int main() { void *vptr; vptr = &i; fun(vptr); return 0; } void fun(void *p) { int **q; q = (int**)&p; printf("%d\n", **q); }
| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Engineer / Developer C - 2of 2 votes
Answersc program to find square root of an interger without using in built functions
- saran August 12, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Intern C