pradeep sahoo


{ City } bangalore
< Country > india
* Profession *
User No # 60529
Total Questions Posted # 0
Total Answers Posted # 3

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 15
Users Marked my Answers as Wrong # 10
Questions / { pradeep sahoo }
Questions Answers Category Views Company eMail




Answers / { pradeep sahoo }

Question { nvidia, 26484 }

when a process is created using fork(). what is shared
between parent process and child process.
1.Heap 2. stack 3. shared memory segments 4. I/O handles


Answer

this is correct but partially. there is something called COW(copy on write). stack is not copied until one of them(parent or child) tries to write into it. if the child immediately calls exec then there is not need to copy the stack at all. As practically in most of the cases child process does an exec call, this unnecessary copy of huge stack is avoided by delaying it till its written into.

Is This Answer Correct ?    12 Yes 3 No

Question { TCS, 16317 }

write an interactive program to generate the divisors of a
given integer.


Answer

same program as above, optimising it a little bit.

#include
int main()
{
int n,i=1;
printf("Value for n\n");
scanf("%d\n",&n);
while(i <= n/2)
{
if(n%i == 0)
printf("%d\n",i);

i++;
}
printf("%d\n",n);
}

Is This Answer Correct ?    2 Yes 7 No


Question { Verifone, 13568 }

struct ptr
{
int a;
char b;
int *p;
}abc;
what is d sizeof structure without using "sizeof" operator??


Answer

In Linux, its 12 bytes.
int a ------- 4 bytes
char b ------- 1 byte.
but as the next element is integer, it wont fit in the
remaining 3 bytes left after the "char b" occupies the first byte of the 4 byte chunk. so these 3 bytes wont be used for storing "int *p". these will be padded. next 4 bytes will be used for storing *p.

to prove it.

int size;
size = (&(abc.p) + sizeof(abc.p)) - &abc.a ;
printf("size = %d",size);

Is This Answer Correct ?    1 Yes 0 No