Online C Programming Test:: C Programming Test - Random: CA Current Affairs GK Engineering Interview Online Test Puzzles
Online C Programming Test:: C Programming Test - Random: CA Current Affairs GK Engineering Interview Online Test Puzzles
Online C Programming Test:: C Programming Test - Random: CA Current Affairs GK Engineering Interview Online Test Puzzles
Search...
Home Aptitude Logical Verbal CA Current Affairs GK Engineering Interview Online Test Puzzles
Marks : 0/20
Total number of questions : 20
Number of answered questions : 0
Number of unanswered questions : 20
int main()
{
int i=3, j=4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf("%d, %d\n", k, l);
return 0;
}
A.12, 12
B.7, 7
C.7, 12
D.12, 7
Explanation:
Step 1: int i=3, j=4, k, l; The variables i, j, k, l are declared as an integer type and variable i, j are initialized to 3, 4
respectively.
https://www.indiabix.com/online-test/c-programming-test/random 1/12
8/10/2018 Test Result
In the function addmult(). The variable kk, ll are declared as an integer type int kk, ll;
int main()
{
char *argv[] = {"ab", "cd", "ef", "gh"};
fun(argv);
return 0;
}
void fun(char **p)
{
char *t;
t = (p+= sizeof(int))[-1];
printf("%s\n", t);
}
A.ab
B.cd
C.ef
D.gh
Explanation:
The output for the above program will be cd in Windows (Turbo C) and gh in Linux (GCC).
To understand it better, compile and execute the above program in Windows (with Turbo C compiler) and in Linux
(GCC compiler).
Explanation:
"fflush()" flush any buffered output associated with filename, which is either a file opened for writing or a shell
command for redirecting output to a pipe or coprocess.
Example:
fflush(FilePointer);
fflush(NULL); flushes all streams.
Explanation:
https://www.indiabix.com/online-test/c-programming-test/random 3/12
8/10/2018 Test Result
6.Which statement will you add in the following program to work it correctly?
#include<stdio.h>
int main()
{
printf("%f\n", log(36.0));
return 0;
}
A.#include<conio.h>
B.#include<math.h>
C.#include<stdlib.h>
D.#include<dos.h>
Explanation:
math.h is a header file in the standard library of C programming language designed for basic mathematical
operations.
#include<stdio.h>
#include<string.h>
int main()
{
char str1[5], str2[5];
int i;
gets(str1);
gets(str2);
i = strcmp(str1, str2);
printf("%d\n", i);
return 0;
}
A.Unpredictable integer value
B.0
C.-1
D.Error
https://www.indiabix.com/online-test/c-programming-test/random 4/12
8/10/2018 Test Result
Explanation:
gets() gets collects a string of characters terminated by a new line from the standard input stream stdin.
The gets(str1) read the input string from user and store in variable str1.
The gets(str2) read the input string from user and store in variable str2.
The code i = strcmp(str1, str2); The strcmp not only returns -1, 0 and +1, but also other negative or positive values.
So the value of i is "unpredictable integer value".
8. What will be the output of the program (Turbo C in 16 bit platform DOS) ?
#include<stdio.h>
#include<string.h>
int main()
{
char *str1 = "India";
char *str2 = "BIX";
char *str3;
str3 = strcat(str1, str2);
printf("%s %s\n", str3, str1);
return 0;
}
A.IndiaBIX India
B.IndiaBIX IndiaBIX
C.India India
D.Error
Explanation:
9.Are the expressions arr and &arr same for an array of 10 integers?
A.Yes
B.No
Explanation:
https://www.indiabix.com/online-test/c-programming-test/random 5/12
8/10/2018 Test Result
Both mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of
ints.
#include<stdio.h>
int main()
{
int (*p)() = fun;
(*p)();
return 0;
}
int fun()
{
printf("IndiaBix.com\n");
return 0;
}
A.Error: in int(*p)() = fun;
B.Error: fun() prototype not defined
C.No error
D.None of these
Explanation:
The compiler will not know that the function int fun() exists. So we have to define the function prototype of int
fun();
To overcome this error, see the below program
#include<stdio.h>
int fun(); /* function prototype */
int main()
{
int (*p)() = fun;
(*p)();
return 0;
}
int fun()
{
printf("IndiaBix.com\n");
return 0;
}
11. malloc() allocates memory from the heap and not from the stack.
A.True
B.False
12. Are the three declarations char **apple, char *apple[], and char apple[][] same?
A.True
B.False
Explanation:
Here we are checking a > 10 means 5 > 10. Hence this condition will be failed. So it prints variable str.
https://www.indiabix.com/online-test/c-programming-test/random 7/12
8/10/2018 Test Result
int main()
{
float s=10, u=30, t=2, a;
a = 2*(s-u*t)/SQUARE(t);
printf("Result = %f", a);
return 0;
}
A.Result = -100.000000
B.Result = -25.000000
C.Result = 0.000000
D.Result = 100.000000
Explanation:
The macro function SQUARE(x) x*x calculate the square of the given number 'x'. (Eg: 102)
Step 1: float s=10, u=30, t=2, a; Here the variable s, u, t, a are declared as an floating point type and the variable s,
u, t are initialized to 10, 30, 2.
=> a = 2 * (10 - 30 * 2) / 2 * 2;
=> a = 2 * (-50) / 2 * 2 ;
=> a = 2 * (-25) * 2 ;
=> a = (-50) * 2 ;
=> a = -100;
https://www.indiabix.com/online-test/c-programming-test/random 8/12
8/10/2018 Test Result
static int a[20];
int i = 0;
a[i] = i ;
printf("%d, %d, %d\n", a[0], a[1], i);
return 0;
}
A.1, 0, 1
B.1, 1, 1
C.0, 0, 0
D.0, 1, 0
Explanation:
Step 1: static int a[20]; here variable a is declared as an integer type and static. If a variable is declared as static
and it will be automatically initialized to value '0'(zero).
Step 2: int i = 0; here vaiable i is declared as an integer type and initialized to '0'(zero).
Step 3: a[i] = i ; becomes a[0] = 0;
Step 4: printf("%d, %d, %d\n", a[0], a[1], i);
Here a[0] = 0, a[1] = 0(because all staic variables are initialized to '0') and i = 0.
Step 4: Hence the output is "0, 0, 0".
#include<stdio.h>
int main()
{
int x=4, y, z;
y = --x;
z = x--;
printf("%d, %d, %d\n", x, y, z);
return 0;
}
A.4, 3, 3
B.4, 3, 2
C.3, 3, 2
D.2, 3, 3
Explanation:
Step 1: int x=4, y, z; here variable x, y, z are declared as an integer type and variable x is initialized to 4.
Step 2: y = --x; becomes y = 3; because (--x) is pre-decrement operator.
Step 3: z = x--; becomes z = 3;. In the next step variable x becomes 2, because (x--) is post-decrement operator.
Step 4: printf("%d, %d, %d\n", x, y, z); Hence it prints "2, 3, 3".
17.Which header file should you include, if you are going to develop a function, which can accept variable number of
arguments?
A.varagrg.h
B.stdlib.h
C.stdio.h
D.stdarg.h
18. Which of the following statements are correct about the program?
#include<stdio.h>
int main()
{
printf("%p\n", main());
return 0;
}
A.It prints garbage values infinitely
B.Runs infinitely without printing anything
C.Error: main() cannot be called inside printf()
D.No Error and print nothing
Explanation:
In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack overflow.
19. 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';
https://www.indiabix.com/online-test/c-programming-test/random 10/12
8/10/2018 Test Result
do
{
*--ptr = "0123456789abcdef"[num %base];
num /=base;
}while(num!=0);
return ptr;
}
A.It converts a number to a given base.
B.It converts a number to its equivalent binary.
C.It converts a number to its equivalent hexadecimal.
D.It converts a number to its equivalent octal.
int main()
{
char c=48;
int i, mask=01;
for(i=1; i<=5; i++)
{
printf("%c", c|mask);
mask = mask<<1;
}
return 0;
}
A.12400
B.12480
C.12500
D.12556
Feedback
Quality of the Test : -- Select --
Comments:
...
Submit Feedback
© 2009 - 2018 by IndiaBIX™ Technologies. All Rights Reserved. | Copyright | Terms of Use & Privacy Policy
https://www.indiabix.com/online-test/c-programming-test/random 12/12