Hi,
Please answer the below questions....thanks
1) How can I free the memory from main(). But the memory was
allocated in function a().
void a()
{
char *b=malloc(10);
}
main()
{
a();
}
2) How can I return the local pointer variable?
main()
{
char *a=result();
}
char * result()
{
char *b = malloc(10);
return b /* I hope this would die once the program gets back to
the caller. But, somehow this needs to be achieved */
}
3) Is there any disadvantage of returning a static variable from
function? Assume the "static" variable is declared globally.
4) Why realloc is inefficient? How many possible ways are there
to overcome inefficiency using realloc itself? Or if not possible
using realloc then what other function we could use.
5) I have a text file which has some content in it and the words
can repeat. For ex: words like "the", "then" may repeat. The user
will type a "word" to be searched in a file and the "count" for that
word should get displayed.
Can anyone suggest me the logic for the above.
Basic restrictions: Temporary array and strstr() should not be used.
6) I have a text file (file size is more than 2 GB) and I want to
find out a given word? The word could be available anywhere in the
file.
Can anyone suggest me the logic for the above.
Basic restrictions: I cannot read the whole file in an array. I cannot read all the lines one by one using
fgets()
7) I have a "static" function in a file say
static int sum(int a, int b);
What does this mean?
I know in C "static functions" are local to the file. But,
interviewer expected something else. What could be that?
8) Can anyone tell me a real-time example for "abstract"
classes? Interviewer accepted the definitions and the basic examples
which I explained. He wanted a real world scenario? Have any worked
on C++ please let me know about the same.