C Program Question
C Program Question
What will be the content of 'file.c' after executing the following program?
#include<stdio.h>
int main()
{
FILE *fp1, *fp2;
fp1=fopen("file.c", "w");
fp2=fopen("file.c", "w");
fputc('A', fp1);
fputc('B', fp2);
fclose(fp1);
fclose(fp2);
return 0;
}
2.
What will be the output of the program ?
#include<stdio.h>
int main()
{
int k=1;
printf("%d == 1 is" "%s\n", k, k==1?"TRUE":"FALSE");
return 0;
}
3.
What will be the output of the program ?
#include<stdio.h>
char *str = "char *str = %c%s%c; main(){ printf(str, 34, str, 34);}";
int main()
{
printf(str, 34, str, 34);
return 0;
}
4.
If the file 'source.txt' contains a line "Be my friend" which of the following w
ill be the output of below program?
#include<stdio.h>
int main()
{
FILE *fs, *ft;
char c[10];
fs = fopen("source.txt", "r");
c[0] = getc(fs);
fseek(fs, 0, SEEK_END);
fseek(fs, -3L, SEEK_CUR);
fgets(c, 5, fs);
puts(c);
return 0;
}
5.
What will be the output of the program ?
#include<stdio.h>
int main()
{
float a=3.15529;
printf("%2.1f\n", a);
return 0;
}
11.
What will be the output of the program ?
#include<stdio.h>
int main()
{
int a=250;
printf("%1d\n", a);
return 0;
}
12.
What will be the output of the program ?
#include<stdio.h>
int main()
{
FILE *fp;
13.
What will be the output of the program if value 25 given to scanf()?
#include<stdio.h>
int main()
{
int i;
printf("%d\n", scanf("%d", &i));
return 0;
}
1.
Point out the error in the program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned char;
FILE *fp;
fp=fopen("trial", "r");
if(!fp)
{
printf("Unable to open file");
exit(1);
}
fclose(fp);
return 0;
}
2.
Point out the error in the program?
#include<stdio.h>
int main()
{
char ch;
int i;
scanf("%c", &i);
scanf("%d", &ch);
printf("%c %d", ch, i);
return 0;
}
3.
Point out the error in the program?
#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("trial", "r");
fseek(fp, "20", SEEK_SET);
fclose(fp);
return 0;
}
4.
Point out the error in the program?
#include<stdio.h>
/* Assume there is a file called 'file.c' in c:\tc directory. */
int main()
{
FILE *fp;
fp=fopen("c:\tc\file.c", "r");
if(!fp)
printf("Unable to open file.");
fclose(fp);
return 0;
}
5.
Point out the error/warning in the program?
#include<stdio.h>
int main()
{
unsigned char ch;
FILE *fp;
fp=fopen("trial", "r");
while((ch = getc(fp))!=EOF)
printf("%c", ch);
fclose(fp);
return 0;
}
3.
What will be the output of the program ?
#include<stdio.h>
int main()
{
int x=30, *y, *z;
y=&x; /* Assume address of x is 500 and integer is 4 byte size */
z=y;
*y++=*z++;
x++;
printf("x=%d, y=%d, z=%d\n", x, y, z);
return 0;
}
4.
What will be the output of the program ?
#include<stdio.h>
int main()
{
char str[20] = "Hello";
char *const p=str;
*p='M';
printf("%s\n", str);
return 0;
}
5.
What will be the output of the program If the integer is 4bytes long?
#include<stdio.h>
int main()
{
int ***r, **q, *p, i=8;
p = &i;
q = &p;
r = &q;
printf("%d, %d, %d\n", *p, **q, ***r);
return 0;
}
21.
What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
int i, n;
char *x="Alice";
n = strlen(x);
*x = x[n];
for(i=0; i<=n; i++)
{
printf("%s ", x);
x++;
}
printf("\n", x);
return 0;
}
22.
What will be the output of the program ?
#include<stdio.h>
int main()
{
int i, a[] = {2, 4, 6, 8, 10};
change(a, 5);
for(i=0; i<=4; i++)
printf("%d, ", a[i]);
return 0;
}
void change(int *b, int n)
{
int i;
for(i=0; i<n; i++)
*(b+1) = *(b+i)+5;
}