© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

1. What are the operations on file?

Ans:

There are different operations that can be carried out on a file. These are:
Creation of a new file
Opening an existing file
Reading from a file
Writing to a file
Moving to a specific location in a file (seeking)
Closing a file  

Ex - 1:  What is the output?
main()
{
FILE *ptr;
char i;
ptr=fopen("zzz.c","r");
while((i=fgetch(ptr))!=EOF)
printf("%c",i);
}

Ans:
contents of zzz.c followed by an infinite loop 

Explanation:
The condition is checked against EOF, it should be checked against NULL.

Ex - 2:  what will be the position of the file marker?
            a: fseek(ptr,0,SEEK_SET);
            b: fseek(ptr,0,SEEK_CUR);
 
Ans :
            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.

Ex - 3:  What is the output?
main()
            {
            char name[10],s[12];
            scanf(" \"%[^\"]\"",s);
            }
            How scanf will execute?
Ans:

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.


SLogix Student Projects
bottom