Professional Documents
Culture Documents
Aptitude Questions and Answer PDF
Aptitude Questions and Answer PDF
#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
: 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.
: 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".
]
#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
: Option B
int main()
{
int i=2;
FUN(i<3);
return 0;
}
A. IndiaBIX...
IndiaBIX...
IndiaBIX
B. IndiaBIX... IndiaBIX...
D. No output
: 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
: 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
: 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
: Option B
×
#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;
: Option B
: Option B
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
: 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
: 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".
char arr[] = "IndiaBIX";
char *ptr = "IndiaBIX";
A. Yes B. No
) Option A
Explanation:
: Option B
c *
+
&
&
A. Yes B. No
: 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
: Option D
c
#include<stdio.h>
#include<stdarg.h>
void display(char *s, ...);
void show(char *t, ...);
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
) Option B
Explanation:
The call to show() is improper. This is not the way to pass variable argument list to a function.
c
, ,
-
A. True
B. False
: 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
: 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
: Option B
%
A. True B. False
) 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;
}
c
&
*
1. !
2. sizeof
3. ~
4. &&
A. 1, 2 B. 1, 3
C. 2, 4 D. 1, 2, 3
) Option D
.- )
: Option B
Explanation:
Example:
Arithmetic operators like ++, -- having Right-to-Left associativity.
Relational operators like >, >= also have Left-to-Right associativity.
] - 01
&
A. Yes B. No
) 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
&
] c
A. use 3.14LD B. use 3.14L
C. use 3.14DL D. use 3.14LF
) Option B
Explanation:
To specify 3.14 as long double, we have to add L to the 3.14. (i.e 3.14L)
r
, 2
&
2
A. True B. False
) 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
: Option C
#include<stdio.h>
int main()
{
int a=10, *j;
void *k;
j=k=&a;
j++;
k++;
printf("%u %u\n", j, k);
return 0;
}
A. Yes
B. No
: 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.
× /
&
,
A. strstr() B. strrev()
C. revstr() D. strreverse()
) Option B
Explanation:
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *str = "IndiaBIX";
Output:
!
3
A. printf(); B. scanf();
C. gets(); D. puts();
) 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:
: 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
: 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.
c
5
A. && operator B. & operator
C. || operator D. ! operator
) 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
: Option A
c
&
2
&
typedef char * string_t;
#define string_d char *;
string_t s1, s2;
string_d s3, s4;
A. Yes
B. No
) 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.
cr 6
-6&
typedef unsigned long int uli;
uli i, j;
unsigned long int x, y;
A. Yes
B. No
: Option A
c
#include<stdio.h>
#define MAX 128
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
)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];
c
& &
&77
77
#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);
: 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
: Option C
c!
#include<stdio.h>
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.
: 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.
%
,
5 8]8
.
A. Yes B. No
) 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
: Option D
Explanation:
It prints "Case1"
A. Yes B. No
: Option B
Explanation:
] 9
5 -
&
&.
A. True B. False
: 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
) Option A
: Option C
C. *k=&a
D. &k=*a
) 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
: 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
)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
) Option B
int main()
{
struct bits
{
float f:2;
}bit;
printf("%d\n", sizeof(bit));
return 0;
}
A. 4
B. 2
) Option C
cc *""4/
A. Yes
B. No
) Option B
c
5
typedef struct s
{
int a;
float b;
}s;
A. Yes
B. No
) Option A
c] *
A. Yes
B. No
) Option A
Explanation:
A structure pointing to itself is called self-referential structures.
int main()
{
char ch, str[10];
while((ch=getc(stdin))!= EOF)
putc(ch, stdout);
return 0;
}
A. mycopy > sourcefile > targetfile
Explanation:
) 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
&
& c%cc%ccccc%%%c%c
&
,
A. Decimal system
B. Hexadecimal system
C. Octal system
D. No need to convert
) Option B
Explanation:
Hexadecimal system is better, because each 4-digit binary represents one Hexadecimal digit.
C. -1
D. 2
) 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
) Option B
) Option A
C. 4, 4, 2
D. 2, 4, 8
) Option C
c
#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
) 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
: 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.
) 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
,
A. True
B. False
) Option A
Explanation:
True, the programmer tells the compiler to include the preprocessor when compiling.
r
6
&
A. True
B. False
) 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
) 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
) 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
: 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
) Option A
c%
7
7
7,7
,
A. 'c' means argument control 'v' means argument vector
: Option C
cc
#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
) Option C
C. 2
D. Error
) 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
: Option D
Explanation:
c
#include<stdio.h>
#include<stdlib.h>
int fun(const union employee *e);
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
) Option B
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);
) Option D
c
&
7
&
7
A. True
B. False
) 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
) Option C
c× /
,
;
-
-
,
-
A. Yes
B. No
) Option B
c! <
"A pointer to an array of three chars".
A. char *ptr[3]();
B. char (*ptr)*[3];
C. char (*ptr[3])();
D. char (*ptr)[3];
: Option D
%
char far *far *scr;
char far far** scr;
A. Yes
B. No
) Option B
c
#include<stdio.h>
int main()
{
int x = 30, y = 40;
if(x == y)
printf("x is equal to y\n");
: Option A
Explanation:
printf("x is less than y\n") here ; is added to the end of this statement.
/
A. True
B. False
) Option A
Explanation:
]
&
&
*
A. /+*-
B. *-/+
C. +-/*
D. /*+-
: 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
) Option B
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
) Option B
int main()
{
printf(5+"Good Morning\n");
return 0;
}
A. Good Morning
B. Good
C. M
D. Morning
: Option D
Explanation:
printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.
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
) 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
×
#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
: 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
) Option A
c% 7
-7
8= & 8
#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();
) 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
) Option B
Explanation:
Instead of 20 use 20L since fseek() need a long offset value.
C. two
D. three
)Option B
C. Error
D. Garbage value
) Option C
) Option C
cr
#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.
) Option A
c
#include<stdio.h>
#define MAX 128
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
: 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 <
"An array of three pointers to chars".
A. char *ptr[3]();
B. char *ptr[3];
C. char (*ptr[3])();
D. char **ptr[3];
) Option B
c×
&
int *f();
A. f is a pointer variable of function type.
C. f is a function pointer.
) 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
) Option C
% *
&
&
A. Yes
B. No
) Option A
Explanation:
Do like this fprintf(stdout, "%s %d %f", str, i, a);