C Interview Questions
- 0of 0 votes
Answers"Simple Parallel Crypto"
- Pia December 04, 2009
We need a utility that will perform a simple XOR crypto transform. They key will be given as a set of bytes in an external file and the number of bytes in the key will dictate the "chunk size". The plain text data will be given on stdin and the utility must break it into chunk-size sections and XOR it against the key and write the cypher text it to stdout. After each chunk is processed the key is rotated left by one bit to make a new key. This means that the key will repeat every N chunks, where N is the number of bits in the key. The plain text may not be a multiple of the chunk size in length. The plain text may also be very large, far exceeding the available memory+swap space in the system.
In addition to just performing the algorithm, the utility needs to scale so that multiple chunks of plain text can be efficiently processed in parallel on multi-core/multi-CPU machines. As such, a number of threads must be created to process chunks of data concurrently. Regardless of the number of threads, the output cypher text must remain the same.
Any errors/status must come out on stderr.
Required Command Line Options:
-k <filename> Specify the key file
-n # Number of threads to create
Example:
The keyfile contains two bytes: 0xF0 0xF0
The plain text file has the bytes: 0x01 0x02 0x03 0x04 0x11 0x12 0x13 0x14
encrypt -k keyfile -n 1 < plain > cypher
The cypher text has the bytes: 0xF1 0xF2 0xE2 0xE5 0xD2 0xD1 0x94 0x93
Implementation Details/Notes:
The utility can be written in C/C++. If C/C++, it should build and run on a POSIX system (like Linux or Mac OS X). A good way to generate keyfiles and plain text files is as follows:
dd if=/dev/urandom of=plain bs=4096 count=4096
dd if=/dev/random of=keyfile bs=4096 count=1| Report Duplicate | Flag | PURGE
Apple Software Engineer / Developer Algorithm C - 0of 0 votes
AnswersDifference between Macro and inline?
- ross December 03, 2009
Why static is not used to define global/local buffer?
write a program to print Fibonacci series?
what is the C++ equivalent of linked list?| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C - 1of 1 vote
AnswersWrite a function to add an array of numbers.
- June December 03, 2009| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer Application / UI Design Arrays C C++ Coding - 2of 2 votes
Answersfind the longest palindrome in a string?
- handiaya November 09, 2009| Report Duplicate | Flag | PURGE
Microsoft Amazon Software Engineer / Developer Algorithm Arrays C++ Coding String Manipulation C - 0of 0 votes
AnswersFor the following piece of code:
- DesiGrad October 21, 2009
func(int d)
{
int temp;
while(temp)
temp--;
}
How does the compiler behave differently if the variable temp is declared with the volatile 'qualifier' ?| Report Duplicate | Flag | PURGE
Qualcomm Software Engineer / Developer C - 0of 0 votes
AnswersThis question was asked by the device driver's team: Can a variable be declared with both the 'const' and 'volatile' qualifiers ?
- DesiGrad October 21, 2009| Report Duplicate | Flag | PURGE
Qualcomm Software Engineer / Developer C - 0of 0 votes
AnswersWrite down the C code to remove the substring from the main string. This should be done recursively.
- someone September 26, 2009
e.g
main string = "hello xyydd"
sub string = "yd"
o/p = "hello x"
#1 recursion o/p = "hello xyd" //first "yd" removed but it formed new matching substring that has to be removed in next recursion
#2 o/p = "hello x"| Report Duplicate | Flag | PURGE
HCL America Software Engineer / Developer C - 0of 0 votes
AnswersThe Chef has one long loaf of bread. Let us say, of length 1. He wants to cut it into as many little loaves as he can. But he wants to adhere to the following rule: At any moment, the length of the longest loaf which he possesses may not be larger than the length of shortest one, times some constant factor. Every time, he is only allowed to cut exactly one loaf into two shorter ones.
- pirateMaster September 23, 2009
Input
One floating-point number, 1 k 1.999, meaning the stated constant factor.
Output
First, you should output one number n, the maximal achievable number of loaves for the given value of the constant factor. Then, you should output any proof that this number of loaves is in fact achievable: n-1 descriptions of cutting, using the following notation. At each step, you print two numbers: first, the index of the loaf that you want to cut into two parts; second, the length of the newly created loaf (cut off from the original one). It is assumed that the starting loaf has index 0. Each newly created loaf will be given the lowest possible free integer index (so, at the ith step this will be i). Each time, the size of size of the original loaf will be decreased by the size of the newly created loaf.
Example
Input:
1.5
Output:
4
0 0.4
0 0.3
1 0.2| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer C - 0of 0 votes
Answersint * p= NULL;
- Franko September 23, 2009
p = (int*) malloc(0);
what will be the value of p?| Report Duplicate | Flag | PURGE
Yahoo Software Engineer / Developer C - 0of 0 votes
AnswersWrite a program htoi(char *) to convert a given hexadecimal value to decimal.
- Vaishnavi September 21, 2009| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer C - 0of 0 votes
AnswersGDB. How to catch corruption of a structure member using GDB?
- Anon September 17, 2009| Report Duplicate | Flag | PURGE
Juniper Networks Software Engineer / Developer C - 0of 0 votes
AnswersWhat is the difference between pointer and reference. Where do we use reference instead of pointer?
- Jonson September 11, 2009| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C - 0of 0 votes
AnswersI want to calculate the factorial for numbers in the range 1 to 100. For small numbers, the function works but for bigger numbers for example 100! it returns incorrect result. Any ways to handle factorial of large numbers in C ?.
- LLOLer September 08, 2009| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C - 0of 0 votes
Answersvoid main()
- venu.pado September 02, 2009
{
int *p = 1;
p++;
printf("%d", p);
}
What will be the output, and why?| Report Duplicate | Flag | PURGE
Software Engineer / Developer C - 0of 0 votes
AnswersWrite an printhex function which implements "%x" in printf without using printf.
- CUNOMAD August 25, 2009
Example :-
printhex(10) output is A .| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer C - 0of 0 votes
AnswersWhat happens when the following piece of code is executed?
- CUNOMAD August 09, 2009
Char *ptr;
While(1) ptr = malloc(1024*1024);| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer C Debugging Operating System - 0of 0 votes
Answersdiff between malloc and calloc
- Anonymous July 31, 2009| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer C - 0of 0 votes
AnswersWhat does 'static' keyword do? Given a function as follows:
- webchic April 06, 2009
int foo() {
static int i;
return i++;
}
What is the value of i, if foo is called twice?
Should you make any changes if it is a multithreaded program?| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C - 0of 0 votes
AnswersWhat is the difference between pass by value and pass by reference?
- Asha February 12, 2009| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C - 0of 0 votes
AnswersChar a[]=”abc” , char *a=”abc”; sizeof both? Where is “abc ” stored and whr is a and *a stored?
- Asha February 12, 2009| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C - 0of 0 votes
AnswersWhat is a pointer?
- Asha February 12, 2009| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C - 0of 0 votes
Answersdone(int,int) throw(const char*,RangeErr);
- Anonymous January 20, 2009
What "done" does in this code?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C - 0of 0 votes
Answerstypedef const char *month Table[3]
- Anonymous January 16, 2009
Create two monthTable arrays and initialize one of the two.| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C - 4of 0 votes
AnswersI was given a simple code which had strUppr() function and asked to find the bugs in the code.
- Stud January 16, 2009
Bugs were related to following topics
1. Return value of the function was pointer to an array which is wrong.
2. A while loop with length of a string was written. There length of string was not considered till the end of the array.
3. A range of characters were compared. If (x>a && x<z). Here the bug is that a and z will not be considered.| Report Duplicate | Flag | PURGE
VMWare Inc Software Engineer / Developer C - 0of 0 votes
Answerstemplate<class T1;class T2;class T3>
- Anonymous January 15, 2009
int Pr(T1 a,T2 b,T3 c)
{
return a*b*c;
}
What's wrong?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C - 0of 0 votes
Answersclass x
- Anonymous January 15, 2009
{int i;
public:
int f() const;
};
{
return i++'
}
What's wrong with this code?| Report Duplicate | Flag | PURGE
Bloomberg LP Software Engineer / Developer C - 1of 1 vote
Answersint x;
- Anonymous January 13, 2009
function()=x;
Is it legal or illegal code?Why?| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer C