Hi
1. What does 2>&1 mean and when is it typically used when added to end of a unix command line ?
&1
# ls -l /mydir >/tmp/out 2>&1
2. Write a shell script which will take a command-line parameter(number) perform a right bit
shift and print the output on standard output.
Or add 1 to the input number in place of right shift.
>>
i=$((i>>1)) For bit shift
i=$((i+1)) for adding one
3. Write a Makefile to compile myprog.c using standard native C compiler and install/copy the output binary(myprog) under /usr/bin.
myprog: myprog.o
gcc -o myprog -g myprog.o
myprog.o: myprog.c
gcc -g -c -Wall myprog.c
install -o myprog /uer/bin
./myprog >
4. What is/are the difference(s) between malloc, calloc, realloc, vmalloc and kmalloc ?
5. Write a structure definition in C, with following members:
account number 13 characters
social security number 10 characters
name 64 characters
address 128 characters
Age 3 characters
Feel free to choose your own data type, for each member. For example Age of a person could
be represented by 1 byte.
stuct obj {
int account_number;
int ssn;
char* name;
char* address;
int age;
} obj;
char name[128] or char *name;
Write a program to calculate factorial of an integer.
n!
#include <stdio>
long long fac(int num) {
if (num<0) return 0;
long long res=1;
int i=1;
for (; i<=num; i++) {
res *=i;
}
return res;
}
int main() {
int num=10;
long long res=fac(num);
printf(“%ld”, res);
return 0;
}
What do the functions atoi() and itoa() do, give an example?
char* name = (char*)malloc(128*sizeof(char));
if(!name) strcpy(name, “123”);
int num=atoi(name);
In C functions, what is the easiest way to pass arrays as arguments ?
void f(int* array);
int main() {
int *array;
f(array);
}
What are register variables? What are advantages of using register variables?
Which is better between insertion, heap sort, and bucket sort, why ?
heap sort O(nlogn)
insertion for array: O(n^2), for list O(n)