Académique Documents
Professionnel Documents
Culture Documents
#include<stdio.h>
int main()
{
char ch;
while(x=0;x<=255;x++)
printf("ASCII value of %d character %c\n", x, x);
return 0;
}
A. The code generates an infinite loop
Answer: Option D
Explanation:
There are 2 errors in this program.
1. "Undefined symbol x" error. Here x is not defined in the program.
2. Here while() statement syntax error.
Answer: Option C
Explanation:
Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable i,
j, k are initialized to -3, 2, 0 respectively.
Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j are
increemented by '1'(one).
Hence the output is "-2, 3, 0, 1".
3. What will be the output of the program?
#include<stdio.h>
int fun(int, int);
typedef int (*pf) (int, int);
int proc(pf, int, int);
int main()
{
printf("%d\n", proc(fun, 6, 6));
return 0;
}
int fun(int a, int b)
{
return (a==b);
}
int proc(pf p, int a, int b)
{
return ((*p)(a, b));
}
A. 6 B. 1
C. 0 D. -1
Answer: Option B
int main()
{
int i=2;
FUN(i<3);
return 0;
}
A. IndiaBIX...
IndiaBIX...
IndiaBIX
B. IndiaBIX... IndiaBIX...
D. No output
Answer: Option B
Explanation:
The macro FUN(arg) prints the statement "IndiaBIX..." untill the while condition is satisfied.
Step 1: int i=2; The variable i is declared as an integer type and initialized to 2.
do
{
if(2 < 3)
printf("IndiaBIX...", "\n");
}while(--2)
After the 2 while loops the value of i becomes '0'(zero). Hence the while loop breaks.
Hence the output of the program is "IndiaBIX... IndiaBIX..."
int main()
{
int x;
x = MAX(3+2, 2+7);
printf("%d\n", x);
return 0;
}
A. 8 B. 9
C. 6 D. 5
Answer: Option B
Explanation:
The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.
Step 1 : int x; The variable x is declared as an integer type.
=> x = (5 > 9 ? 5 : 9)
=> x = 9
Answer: Option C
Explanation:
The macro MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c) returns the biggest of given three
numbers.
=> x = (3+2 >2+7 ? 3+2 > 3+7 ? 3+2 : 3+7: 2+7 > 3+7 ? 2+7 : 3+7)
=> x = 10
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;
}
change(int *b, int n)
{
int i;
for(i=0; i<n; i++)
*(b+1) = *(b+i)+5;
}
A. 7, 9, 11, 13, 15 B. 2, 15, 6, 8, 10
C. 2 4 6 8 10 D. 3, 1, -1, -3, -5
Answer: Option B
8. In the following program add a statement in the function fact(). such that
the factorial gets stored in j.
#include<stdio.h>
void fact(int*);
int main()
{
int i=5, j;
fact(&i);
printf("%d\n", i);
return 0;
}
void fact(int *j)
{
static int s=1;
if(*j!=0)
{
s = s**j;
*j = *j-1;
fact(j);
/* Add a statement here */
}
}
A. j=s; B. *j=s;
C. *j=&s; D. &j=s;
Answer: Option B
Answer: Option B
10. What will be the output of the program if the array begins at address 65486?
#include<stdio.h>
int main()
{
int arr[] = {12, 14, 15, 23, 45};
printf("%u, %u\n", arr, &arr);
return 0;
}
A. 65486, 65488 B. 65486, 65486
C. 65486, 65490 D. 65486, 65487
Answer: Option B
Explanation:
Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and
initialized.
Step 2: printf("%u, %u\n", arr, &arr); Here,
The base address of the array is 65486.
=> arr, &arr is pointing to the base address of the array arr.
Hence the output of the program is 65486, 65486
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
A. Hello B. World
C. Hello World D. WorldHello
Answer: Option C
Explanation:
Step 1: char str1[20] = "Hello", str2[20] = " World"; The variable str1 and str2 is declared as an
array of characters and initialized with value "Hello" and " World" respectively.
Step 2: printf("%s\n", strcpy(str2, strcat(str1, str2)));
=> strcat(str1, str2)) it append the string str2 to str1. The result will be stored in str1. Therefore
str1 contains "Hello World".
=> strcpy(str2, "Hello World") it copies the "Hello World" to the variable str2.
Hence it prints "Hello World".
12. For the following statements will arr[3] and ptr[3] fetch the same
character?
char arr[] = "IndiaBIX";
char *ptr = "IndiaBIX";
A. Yes B. No
Answer: Option A
Explanation:
Answer: Option B
int main()
{
fun1(1, "Apple", "Boys", "Cats", "Dogs");
fun2(2, 12, 13, 14);
return 0;
}
void fun1(int num, ...)
{
char *str;
va_list ptr;
va_start(ptr, num);
str = va_arg(ptr, char *);
printf("%s", str);
}
void fun2(int num, ...)
{
va_list ptr;
va_start(ptr, num);
num = va_arg(ptr, int);
printf("%d", num);
}
A. Dogs 12 B. Cats 14
C. Boys 13 D. Apple 12
Answer: Option D
int main()
{
display("Hello", 4, 12, 13, 14, 44);
return 0;
}
void display(char *s, ...)
{
show(s, ...);
}
void show(char *t, ...)
{
int a;
va_list ptr;
va_start(ptr, s);
a = va_arg(ptr, int);
printf("%f", a);
}
A. Error: invalid function display() call
C. No error
Answer: Option B
Explanation:
The call to show() is improper. This is not the way to pass variable argument list to a function.
Answer: Option B
int main()
{
char huge *near *far *ptr1;
char near *far *huge *ptr2;
char far *huge *near *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(*ptr2), sizeof(**ptr3));
return 0;
}
A. 4, 4, 4 B. 2, 4, 4
C. 4, 4, 2 D. 2, 4, 8
Answer: Option A
int main()
{
char huge *near *ptr1;
char huge *far *ptr2;
char huge *huge *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
return 0;
}
A. 4, 4, 8 B. 2, 4, 4
C. 4, 4, 2 D. 2, 4, 8
Answer: Option B
20. ftell() returns the current position of the pointer in a file stream.
A. True B. False
Answer: Option A
Explanation:
The ftell() function shall obtain the current value of the file-position indicator for the stream
pointed to by stream.
Example:
#include <stdio.h>
int main(void)
{
FILE *stream;
stream = fopen("MYFILE.TXT", "w+");
fprintf(stream, "This is a test");
printf("The file pointer is at byte %ld\n", ftell(stream));
fclose(stream);
return 0;
}
1. Which of the following are unary operators in C?
1. !
2. sizeof
3. ~
4. &&
A. 1, 2 B. 1, 3
C. 2, 4 D. 1, 2, 3
Answer: Option D
Explanation:
Answer: Option B
Explanation:
Example:
Arithmetic operators like ++, -- having Right-to-Left associativity.
Relational operators like >, >= also have Left-to-Right associativity.
Answer: Option B
Explanation:
Because, here even though the value of p is accessed twice it is used to modify two different
objects p and *p
Explanation:
To specify 3.14 as long double, we have to add L to the 3.14. (i.e 3.14L)
5. Preprocessor directive #undef can be used only on a macro that has been
#define earlier
A. True B. False
Answer: Option A
Explanation:
True, #undef can be used only on a macro that has been #define earlier
int main()
{
void *vptr;
vptr = &i;
fun(vptr);
return 0;
}
void fun(void *p)
{
int **q;
q = (int**)&p;
printf("%d\n", **q);
}
A. Error: cannot convert from void** to int** B. Garbage value
C. 0 D. No output
Answer: Option C
Answer: Option B
Explanation:
The following error will be displayed while compiling above program in TurboC.
Compiling PROGRAM.C:
Error PROGRAM.C 8: Size of the type is unknown or zero.
Answer: Option B
Explanation:
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *str = "IndiaBIX";
Output:
Answer: Option C
Explanation:
gets(); collects a string of characters terminated by a new line from the standard input stream
stdin
#include <stdio.h>
int main(void)
{
char string[80];
printf("Enter a string:");
gets(string);
printf("The string input was: %s\n", string);
return 0;
}
Output:
Answer: Option B
Explanation:
Because, In fgets() we can specify the size of the buffer into which the string supplied will be
stored.
int main()
{
FILE *ptr;
char i;
ptr = fopen("myfile.c", "r");
while((i=fgetc(ptr))!=NULL)
printf("%c", i);
return 0;
}
A. Print the contents of file "myfile.c"
C. Infinite loop
D. Error in program
Answer: Option C
Explanation:
The program will generate infinite loop. When an EOF is encountered fgetc() returns EOF.
Instead of checking the condition for EOF we have checked it for NULL. so the program will
generate infinite loop.
12. Which bitwise operator is suitable for checking whether a particular bit is
on or off?
A. && operator B. & operator
C. || operator D. ! operator
Answer: Option B
int main()
{
unsigned int res;
res = (64 >>(2+1-2)) & (~(1<<2));
printf("%d\n", res);
return 0;
}
A. 32 B. 64
C. 0 D. 128
Answer: Option A
14. Is there any difference in the #define and typedef in the following code?
typedef char * string_t;
#define string_d char *;
string_t s1, s2;
string_d s3, s4;
A. Yes
B. No
Answer: Option A
Explanation:
In these declarations, s1, s2 and s3 are all treated as char*, but s4 is treated as a char, which is
probably not the intention.
15. Are the properties of i, j and x, y in the following program same?
typedef unsigned long int uli;
uli i, j;
unsigned long int x, y;
A. Yes
B. No
Answer: Option A
int main()
{
const int max=128;
char array[max];
char string[MAX];
array[0] = string[0] = 'A';
printf("%c %c\n", array[0], string[0]);
return 0;
}
A. Error: unknown max in declaration
C. None of above
D. No error. It prints A A
Answer: Option D
Explanation:
Step 2: const int max=128; The constant variable max is declared as an integer data type and it
is initialized with value 128.
Step 3: char array[max]; This statement reports an error "constant expression required".
Because, we cannot use variable to define the size of array.
To avoid this error, we have to declare the size of an array as static. Eg. char array[10]; or use
macro char array[MAX];
17. Point out the correct statement which correctly free the memory pointed to
by 's' and 'p' in the following program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct ex
{
int i;
float j;
char *s
};
struct ex *p;
p = (struct ex *)malloc(sizeof(struct ex));
p->s = (char*)malloc(20);
return 0;
}
A. free(p); , free(p->s); B. free(p->s); , free(p);
C. free(p->s); D. free(p);
Answer: Option B
int main()
{
fun("IndiaBIX", 1, 4, 7, 11, 0);
return 0;
}
void fun(char *msg, ....)
{
int tot=0;
va_list ptr;
int num;
va_start(ptr, msg);
num = va_arg(ptr, int)
num = va_arg(ptr, int)
printf("%d", num);
}
A. IndiaBIX 1 7 11 0 B. 1
C. 4 D. 7
Answer: Option C
int main()
{
int i;
char c;
for(i=1; i<=5; i++)
{
scanf("%c", &c); /* given input is 'a' */
printf("%c", c);
ungetc(c, stdin);
}
return 0;
}
A. aaaa B. aaaaa
C. Garbage value. D. Error in ungetc statement.
Answer: Option B
Explanation:
Loop 1:
scanf("%c", &c); Here we give 'a' as input.
printf("%c", c); prints the character 'a' which is given in the previous "scanf()" statement.
ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.
Loop 2:
Here the scanf("%c", &c); get the input from "stdin" because of "ungetc" function.
printf("%c", c); Now variable c = 'a'. So it prints the character 'a'.
ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.
20. scanf() or atoi() function can be used to convert a string like "436" in to
integer.
A. Yes B. No
Answer: Option A
Explanation:
scanf is a function that reads data with specified format from a given string stream source.
scanf("%d",&number);
D. No Error
Answer: Option D
Explanation:
It prints "Case1"
A. Yes B. No
Answer: Option B
Explanation:
Answer: Option B
Explanation:
False, A macro just replaces each occurrence with the code assigned to it. e.g. SQUARE(3) with
((3)*(3)) in the program.
A function is compiled once and can be called from anywhere that has visibility to the funciton.
int main()
{
char str[20] = "Hello";
char *const p=str;
*p='M';
printf("%s\n", str);
return 0;
}
A. Mello
B. Hello
C. HMello
D. MHello
Answer: Option A
Answer: Option C
6. In the following program add a statement in the function fun() such that
address of a gets stored in j?
#include<stdio.h>
int main()
{
int *j;
void fun(int**);
fun(&j);
return 0;
}
void fun(int **k)
{
int a=10;
/* Add a statement here */
}
A. **k=a;
B. k=&a;
C. *k=&a
D. &k=*a
Answer: Option C
int main()
{
static int arr[] = {0, 1, 2, 3, 4};
int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};
int **ptr=p;
ptr++;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
*ptr++;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
*++ptr;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
++*ptr;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
return 0;
}
A. 0, 0, 0
1, 1, 1
2, 2, 2
3, 3, 3
B. 1, 1, 2
2, 2, 3
3, 3, 4
4, 4, 1
C. 1, 1, 1
2, 2, 2
3, 3, 3
3, 4, 4
D. 0, 1, 2
1, 2, 3
2, 3, 4
3, 4, 5
Answer: Option C
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}
A. 10
B. 20
C. 30
D. 0
Answer: Option B
int main()
{
struct a
{
category:5;
scheme:4;
};
printf("size=%d", sizeof(struct a));
return 0;
}
A. Error: invalid structure member in printf
C. No error
D. None of above
Answer: Option B
int main()
{
struct bits
{
float f:2;
}bit;
printf("%d\n", sizeof(bit));
return 0;
}
A. 4
B. 2
Answer: Option C
11. A pointer union CANNOT be created
A. Yes
B. No
Answer: Option B
Answer: Option A
Answer: Option A
Explanation:
A structure pointing to itself is called self-referential structures.
14. How will you use the following program to copy the contents of one file to
another file?
#include<stdio.h>
int main()
{
char ch, str[10];
while((ch=getc(stdin))!= EOF)
putc(ch, stdout);
return 0;
}
A. mycopy > sourcefile > targetfile
Explanation:
15. We should not read after a write to a file without an intervening call to
fflush(), fseek() or rewind()
A. True
B. False
Answer: Option A
Explanation:
True, we should not be able to read a file after writing in that file without calling the below
functions.
int fflush ( FILE * stream ); If the given stream was open for writing and the last i/o operation
was an output operation, any unwritten data in the output buffer is written to the file.
int fseek ( FILE * stream, long int offset, int origin ); Its purpose is to change the file position
indicator for the specified stream.
void rewind ( FILE * stream ); Sets the position indicator associated with stream to the
beginning of the file.
C. Octal system
D. No need to convert
Answer: Option B
Explanation:
Hexadecimal system is better, because each 4-digit binary represents one Hexadecimal digit.
C. -1
D. 2
Answer: Option B
int main()
{
enum color{red, green, blue};
typedef enum color mycolor;
mycolor m = red;
printf("%d", m);
return 0;
}
A. 1
B. 0
C. 2
D. red
Answer: Option B
19. While defining a variable argument list function we drop the ellipsis(...)?
A. Yes
B. No
Answer: Option A
C. 4, 4, 2
D. 2, 4, 8
Answer: Option C
1. What will be the output of the program?
#include<stdio.h>
int main()
{
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
c = 200;
printf("b = %d c = %d\n", b, c);
return 0;
}
A. b = 300 c = 200
B. b = 100 c = garbage
C. b = 300 c = garbage
D. b = 100 c = 200
Answer: Option D
Explanation:
int main()
{
int c;
c = check(10, 20);
printf("c=%d\n", c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(*p): return(*q);
}
A. Print 10
B. Print 20
C. Print 1
D. Compile error
Answer: Option D
Explanation:
There is an error in this line i>=45 ? return(*p): return(*q);. We cannot use return keyword in
the terenary operators.
Answer: Option C
Explanation:
The macro #define SI(p, n, r) float si; si=p*n*r/100; contains the error. To remove this error, we
have to modify this macro to
Explanation:
True, the programmer tells the compiler to include the preprocessor when compiling.
Answer: Option A
Explanation:
True, the header file contains classes, function prototypes, structure declaration, macros.
int main()
{
void fun(int, int[]);
int arr[] = {1, 2, 3, 4};
int i;
fun(4, arr);
for(i=0; i<4; i++)
printf("%d,", arr[i]);
return 0;
}
void fun(int n, int arr[])
{
int *p=0;
int i=0;
while(i++ < n)
p = &arr[i];
*p=0;
}
A. 2, 3, 4, 5
B. 1, 2, 3, 4
C. 0, 1, 2, 3
D. 3, 2, 1 0
Answer: Option B
Explanation:
Step 1: void fun(int, int[]); This prototype tells the compiler that the function fun() accepts one
integer value and one array as an arguments and does not return anything.
Step 2: int arr[] = {1, 2, 3, 4}; The variable a is declared as an integer array and it is initialized to
Step 4: fun(4, arr); This function does not affect the output of the program. Let's skip this
function.
Step 5: for(i=0; i<4; i++) { printf("%d,", arr[i]); } The for loop runs untill the variable i is less
than '4' and it prints the each value of array a.
int main()
{
char t;
char *p1 = "India", *p2;
p2=p1;
p1 = "BIX";
printf("%s %s\n", p1, p2);
return 0;
}
A. India BIX
B. BIX India
C. India India
D. BIX BIX
Answer: Option B
Explanation:
Step 1: char *p1 = "India", *p2; The variable p1 and p2 is declared as an pointer to a character
value and p1 is assigned with a value "India".
Step 4: printf("%s %s\n", p1, p2); It prints the value of p1 and p2.
Hence the output of the program is "BIX India".
int main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
strupr(e2.n);
printf("%s\n", e1.n);
return 0;
}
A. Error: Invalid structure assignment
B. DRAVID
C. Dravid
D. No output
Answer: Option B
int main()
{
struct emp
{
char name[25];
int age;
float bs;
};
struct emp e;
e.name = "Suresh";
e.age = 25;
printf("%s %d\n", e.name, e.age);
return 0;
}
A. Error: Lvalue required
D. No error
Answer: Option A
Answer: Option C
11. Which of the following statements are correct about the program?
#include<stdio.h>
int main()
{
unsigned int num;
int i;
scanf("%u", &num);
for(i=0; i<16; i++)
{
printf("%d", (num<<i & 1<<15)?1:0);
}
return 0;
}
A. It prints all even bits from num
D. Error
Answer: Option C
C. 2
D. Error
Answer: Option B
union employee
{
char name[15];
int age;
float salary;
};
const union employee e1;
int main()
{
strcpy(e1.name, "K");
printf("%s %d %f", e1.name, e1.age, e1.salary);
return 0;
}
A. Error: RValue required
D. No error
Answer: Option D
Explanation:
union employee
{
char name[15];
int age;
float salary;
};
const union employee e1;
int main()
{
strcpy(e1.name, "A");
fun(&e1);
printf("%s %d %f", e1.name, e1.age, e1.salary);
return 0;
}
int fun(const union employee *e)
{
strcpy((*e).name, "B");
return 0;
}
A. Error: RValue required
D. No error
Answer: Option B
15. How will you free the memory allocated by the following program?
#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4
int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}
A. memfree(int p);
B. dealloc(p);
C. malloc(p, 0);
D. free(p);
Answer: Option D
16. malloc() returns a float pointer if memory is allocated for storing float's and
a double pointer if memory is allocated for storing double's.
A. True
B. False
Answer: Option B
int main()
{
display(4, 'A', 'B', 'C', 'D');
return 0;
}
void display(int num, ...)
{
char c, c1; int j;
va_list ptr, ptr1;
va_start(ptr, num);
va_start(ptr1, num);
for(j=1; j<=num; j++)
{
c = va_arg(ptr, int);
printf("%c", c);
c1 = va_arg(ptr1, int);
printf("%d\n", c1);
}
}
A. A, A
B, B
C, C
D, D
B. A, a
B, b
C, c
D, d
C. A, 65
B, 66
C, 67
D, 68
D. A, 0
B, 0
C, 0
C, 0
Answer: Option C
18. The macro va_arg is used to extract an argument from the fixed micro
argument list and advance the pointer to the next argument.
A. Yes
B. No
Answer: Option B
C. char (*ptr[3])();
D. char (*ptr)[3];
Answer: Option D
Answer: Option B
1. Which of the following statements are correct about the program?
#include<stdio.h>
int main()
{
int x = 30, y = 40;
if(x == y)
printf("x is equal to y\n");
Answer: Option A
Explanation:
printf("x is less than y\n") here ; is added to the end of this statement.
Answer: Option A
Explanation:
Answer: Option D
Explanation:
B - Brackets first
O - Orders (ie Powers and Square Roots, etc.)
DM - Division and Multiplication (left-to-right)
AS - Addition and Subtraction (left-to-right)
int main()
{
void fun(char*);
char a[100];
a[0] = 'A'; a[1] = 'B';
a[2] = 'C'; a[3] = 'D';
fun(&a[0]);
return 0;
}
void fun(char *a)
{
a++;
printf("%c", *a);
a++;
printf("%c", *a);
}
A. AB
B. BC
C. CD
D. No output
Answer: Option B
5. If the size of integer is 4bytes. What will be the output of the program?
#include<stdio.h>
int main()
{
int arr[] = {12, 13, 14, 15, 16};
printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
return 0;
}
A. 10, 2, 4
B. 20, 4, 4
C. 16, 2, 2
D. 20, 2, 2
Answer: Option B
int main()
{
printf(5+"Good Morning\n");
return 0;
}
A. Good Morning
B. Good
C. M
D. Morning
Answer: Option D
Explanation:
printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.
7. What will be the output of the program If characters 'a', 'b' and 'c' enter are
supplied as input?
#include<stdio.h>
int main()
{
void fun();
fun();
printf("\n");
return 0;
}
void fun()
{
char c;
if((c = getchar())!= '\n')
fun();
printf("%c", c);
}
A. abc abc
B. bca
C. Infinite loop
D. cba
Answer: Option D
Explanation:
Step 1: void fun(); This is the prototype for the function fun().
The function fun() gets a character input and the input is terminated by an enter key(New line
character). It prints the given character in the reverse order.
Output: cba
8. Which of the following statements are correct about the program below?
#include<stdio.h>
int main()
{
char str[20], *s;
printf("Enter a string\n");
scanf("%s", str);
s=str;
while(*s != '\0')
{
if(*s >= 97 && *s <= 122)
*s = *s-32;
s++;
}
printf("%s",str);
return 0;
}
A. The code converts a string in to an integer
D. Error in code
Answer: Option B
Explanation:
Output:
INDIABIX
struct course
{
int courseno;
char coursename[25];
};
int main()
{
struct course c[] = { {102, "Java"},
{103, "PHP"},
{104, "DotNet"} };
printf("%d", c[1].courseno);
printf("%s\n", (*(c+2)).coursename);
return 0;
}
A. 103 Dotnet
B. 102 Java
C. 103 PHP
D. 104 DotNet
Answer: Option A
10. If the file 'source.txt' contains a line "Be my friend" which of the following
will be the output of below program?
#include<stdio.h>
int main()
{
FILE *fs, *ft;
char c[10];
fs = fopen("source.txt", "r");
c = getc(fs);
fseek(fs, 0, SEEK_END);
fseek(fs, -3L, SEEK_CUR);
fgets(c, 5, fs);
puts(c);
return 0;
}
A. friend
B. frien
C. end
D. Error in fseek();
Answer: Option C
Explanation:
fseek(fs, 0, SEEK_END); moves the file pointer to the end of the file.
fgets(c, 5, fs); read the file from the current position of the file pointer.
int main()
{
FILE *fp;
fp=fopen("trial", "r");
fseek(fp, 20, SEEK_SET);
fclose(fp);
return 0;
}
A. Error: unrecognised Keyword SEEK_SET
C. No error
D. None of above
Answer: Option B
Explanation:
Instead of 20 use 20L since fseek() need a long offset value.
12. What will be the output of the program (myprog.c) given below if it is
executed from the command line?
cmd> myprog one two three
/* myprog.c */
#include<stdio.h>
#include<stdlib.h>
C. two
D. three
Answer: Option B
13. What will be the output of the program (sample.c) given below if it is
executed from the command line?
cmd> sample 1 2 3
/* sample.c */
#include<stdio.h>
C. Error
D. Garbage value
Answer: Option C
14. What will be the output of the program (sample.c) given below if it is
executed from the command line?
cmd> sample friday tuesday sunday
/* sample.c */
#include<stdio.h>
Answer: Option C
15. Which of the following statements are correct about the program?
#include<stdio.h>
char *fun(unsigned int num, int base);
int main()
{
char *s;
s=fun(128, 2);
s=fun(128, 16);
printf("%s\n",s);
return 0;
}
char *fun(unsigned int num, int base)
{
static char buff[33];
char *ptr = &buff[sizeof(buff)-1];
*ptr = '\0';
do
{
*--ptr = "0123456789abcdef"[num %base];
num /=base;
}while(num!=0);
return ptr;
}
A. It converts a number to a given base.
Answer: Option A
int main()
{
char mybuf[] = "India";
char yourbuf[] = "BIX";
char const *ptr = mybuf;
*ptr = 'a';
ptr = yourbuf;
return 0;
}
A. Error: cannot convert ptr const value
C. No error
D. None of above
Answer: Option A
Explanation:
Step 1: char mybuf[] = "India"; The variable mybuff is declared as an array of characters and
initialized with string "India".
Step 2: char yourbuf[] = "BIX"; The variable yourbuf is declared as an array of characters and
initialized with string "BIX".
Step 3: char const *ptr = mybuf; Here, ptr is a constant pointer, which points at a char.
The value at which ptr it points is a constant; it will be an error to modify the pointed character;
There will not be any error to modify the pointer itself.
Step 4: *ptr = 'a'; Here, we are changing the value of ptr, this will result in the error "cannot
modify a const object".
C. char (*ptr[3])();
D. char **ptr[3];
Answer: Option B
C. f is a function pointer.
Answer: Option B
int main()
{
uli a;
u b = -1;
a = -1;
printf("%lu, %lu"a, b);
return 0;
}
A. 4343445454, 4343445454
B. 4545455434, 4545455434
C. 4294967295, 4294967295
D. Garbage values
Answer: Option C
20. Can you use the fprintf() to display the output on the screen?
A. Yes
B. No
Answer: Option A
Explanation:
Do like this fprintf(stdout, "%s %d %f", str, i, a);