Monday, 3 December 2012

Interview apps on C (part 3)


1. We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind() "TRUE/FALSE" ?



2. If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output?

#include<stdio.h>
int main(int argc, char *argv[]){
    int i;
    for(i=0;i<argc;i++)
         printf("%s",argv[i]);
    return 0;
}

a) 1 2 3
b) C:\MYPROG.EXE 1 2 3
c) MYP
d) None of the above



3. If the following program (myprog) is run from the command line as myprog 1 2 3, what would be the output?

#include<stdio.h>
int main(int argc, char *argv[]){
    int i,j=0;
    for(i=0;i<argc;i++)
         j=j+ atoi(argv[i]);
    printf("%d",j);
    return 0;
}

a) 1 2 3
b) 6
c) error
d) "123"



4. If the following program (myprog) is run from the command line as :
myprog monday tuesday wednesday thursday
What would be the output?

#include<stdio.h>
int main(int argc, char *argv[]){
    while(--argc <0)
         printf("%s",*++argv);
    return 0;
}

a) myprog monday tuesday wednesday thursday
b) monday tuesday wednesday thursday
c) myprog tuesday thursday
d) None of the above

Interview apps on C (part 2)


1. What is the output of the following program?

#include<stdio.h>
#define SQR(x) (x*x)
int main(){
    int a,b=3;
    a= SQR(b+2);
    printf("%d",a);
    return 0;
}
a) 25
b) 11
c) error
d) garbage value


2. In which line of the following, an error would be reported?

#include<stdio.h>
1. #define CIRCUM(R) (3.14*R*R);
2. int main()
3. {
4.       float r=1.0,c;
5.       c= CIRCUM(r);
6.       printf("\n%f",c);
7.       if(CIRCUM(r))==6.28)
8.           printf("\nGobbledygook");
9.       return 0;
10. }

a) line 1
b) line 5
c) line 6
d)line 7



3. What is the type of the variable b in the following declaration?

#define FLOATPTR float*
FLOATPTR a,b;

a) float
b) float pointer
c) int
d) int pointer



4. In the following code:

#include"stdio.h";
int main(){
    FILE *fp;
    fp= fopen("trial","r");
}

fp points to:
a) The first character in the file.
b) A structure which contains a "char" pointer which points to the first character in the file.
c) The name of the file.
d) None of the above.

Interview apps on C (part 1)


1. Find out the error if any, in the program.

#include<stdio.h>
int main()
{
    int i=1;
    switch(i)
{
         case 1: printf("\radioactive cats have 18 half-lives");
         break;
         case 1*2+4: printf("\bottle for rent -inquire within");
         break;
}
    return 0;
}



2. Find out the error, if any, in the following program.

#include<stdio.h>
int main()
{
    int a=10,b;
    a= 5 ? b=100 : b=200;
    printf("\n%d",b);
    return 0;
}

Saturday, 1 December 2012

C basic questions - 5


What will the output of the program



extern int j;
void main(){
    int i=0;
    clrscr();
    for(i=0;i<=2;i+=1){
         int j=5;
         printf("%d ",j);
         j++;
    }
    getch();
}
int j=25;

Note : Comment your answers


C basic questions - 4


What will the output of the program


void main(){
    int i=2;
    clrscr();
    for(i=0;i<=3;i++){
         static int i;
         i=i+8;
    }
    printf("%d",i);
    getch();
}

Note : Comment your answers