Friday, 27 June 2014

#18. Concepts in C -- only through Examples & Explanations

This is a continuation of last post. 

Before seeing the answer try to predict it & then see the explanation.

All the Best!!

51) What are the files which are automatically opened when a C file is executed?

52) what will be the position of the file marker?
a: fseek(ptr,0,SEEK_SET);
b: fseek(ptr,0,SEEK_CUR);

53) main()
{
char name[10],s[12];
scanf(" \"%[^\"]\"",s);
}
How scanf will execute?

54) What is the problem with the following code segment?
while ((fgets(receiving array,50,file_ptr)) != EOF);

55) main()
{
main();
}

========================================================
51.
Answer:
stdin, stdout, stderr (standard input,standard output,standard error).

52.
Answer :
a: The SEEK_SET sets the file position marker to the starting of the file.
b: The SEEK_CUR sets the file position marker to the current position
of the file.

53.
Answer:
First it checks for the leading white space and discards it.Then it matches
with a quotation mark and then it reads all character upto another quotation
mark.

54.
Answer & Explanation:
fgets returns a pointer. So the correct end of file check is checking for !=
NULL.

55.
Answer:
Runtime error : Stack overflow.
Explanation:
main function calls itself again and again. Each time the function is called its
return address is stored in the call stack. Since there is no condition to terminate
the function call, the call stack overflows at runtime. So it
terminates the program and results in an error.

To be continued...
========================================================

Thanks for coming till this point!!
VSG
SQL DBA



No comments:

Post a Comment