Online C Programming Test:: C Programming Test - Random: CA Current Affairs GK Engineering Interview Online Test Puzzles

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

8/10/2018 Test Result

Search...

Home Aptitude Logical Verbal CA Current Affairs GK Engineering Interview Online Test Puzzles

Online C Programming Test :: C Programming Test -


Random
Home » Online Test » Online C Programming Test » C Programming Test - Random

Marks : 0/20
Total number of questions : 20
Number of answered questions : 0
Number of unanswered questions : 20

Test Review : View answers and explanation for this test.

1.What will be the output of the program?


#include<stdio.h>

int addmult(int ii, int jj)


{
int kk, ll;
kk = ii + jj;
ll = ii * jj;
return (kk, ll);
}

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

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

The function addmult(i, j); accept 2 integer parameters.

Step 2: k = addmult(i, j); becomes k = addmult(3, 4)

In the function addmult(). The variable kk, ll are declared as an integer type int kk, ll;

kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'.

ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'.

return (kk, ll); It returns the value of variable ll only.

The value 12 is stored in variable 'k'.

Step 3: l = addmult(i, j); becomes l = addmult(3, 4)

kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'.

ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'.

return (kk, ll); It returns the value of variable ll only.

The value 12 is stored in variable 'l'.

Step 4: printf("%d, %d\n", k, l); It prints the value of k and l

Hence the output is "12, 12".

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

2.If int is 2 bytes wide.What will be the output of the program?


#include <stdio.h>
void fun(char**);

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Since C is a machine dependent language sizeof(int) may return different values.


https://www.indiabix.com/online-test/c-programming-test/random 2/12
8/10/2018 Test Result

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).

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

3.What is the purpose of fflush() function.


A.flushes all streams and specified streams.
B.flushes only specified stream.
C.flushes input/output buffer.
D.flushes file buffer.

Your Answer: Option (Not Answered)

Correct Answer: Option A

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.

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum

4. Declare the following statement?


"A pointer to a function which receives an int pointer and returns float pointer".
A.float *(ptr)*int;
B. float *(*ptr)(int)
C. float *(*ptr)(int*)
D.float (*ptr)(int)

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum

5. Macros with arguments are allowed


A.True
B.False

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:
https://www.indiabix.com/online-test/c-programming-test/random 3/12
8/10/2018 Test Result

True, A macro may have arguments.

Example: #define CUBE(X)(X*X*X)

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

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>

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

math.h is a header file in the standard library of C programming language designed for basic mathematical
operations.

Declaration syntax: double log(double);

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum

7.What will be the output of the program ?

#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

Your Answer: Option (Not Answered)

Correct Answer: Option A

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".

printf("%d\n", i); It prints the value of variable i.

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

It prints 'IndiaBIX IndiaBIX' in TurboC (in 16 bit platform).

It may cause a 'segmentation fault error' in GCC (32 bit platform).

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

9.Are the expressions arr and &arr same for an array of 10 integers?
A.Yes
B.No

Your Answer: Option (Not Answered)

Correct Answer: Option B

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.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

10.Point out the error in the following program.

#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

Your Answer: Option (Not Answered)

Correct Answer: Option B

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;
}

Learn more problems on : Declarations and Initializations

Discuss about this problem : Discuss in Forum

11. malloc() allocates memory from the heap and not from the stack.
A.True
B.False

Your Answer: Option (Not Answered)


https://www.indiabix.com/online-test/c-programming-test/random 6/12
8/10/2018 Test Result

Correct Answer: Option A

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum

12. Are the three declarations char **apple, char *apple[], and char apple[][] same?
A.True
B.False

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

13. What will be the output of the program?


#include<stdio.h>
int main()
{
char str[]="C-program";
int a = 5;
printf(a >10?"Ps\n":"%s\n", str);
return 0;
}
A.C-program
B.Ps
C.Error
D.None of above

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Step 1: char str[]="C-program"; here variable str contains "C-program".


Step 2: int a = 5; here variable a contains "5".
Step 3: printf(a >10?"Ps\n":"%s\n", str); this statement can be written as

if(a > 10)


{
printf("Ps\n");
}
else
{
printf("%s\n", str);
}

Here we are checking a > 10 means 5 > 10. Hence this condition will be failed. So it prints variable str.

Hence the output is "C-program".

Learn more problems on : Control Instructions

https://www.indiabix.com/online-test/c-programming-test/random 7/12
8/10/2018 Test Result

Discuss about this problem : Discuss in Forum

14.What will be the output of the program?


#include<stdio.h>
#define SQUARE(x) x*x

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

Your Answer: Option (Not Answered)

Correct Answer: Option A

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.

Step 2: a = 2*(s-u*t)/SQUARE(t); becomes,

=> a = 2 * (10 - 30 * 2) / t * t; Here SQUARE(t) is replaced by macro to t*t .

=> a = 2 * (10 - 30 * 2) / 2 * 2;

=> a = 2 * (10 - 60) / 2 * 2;

=> a = 2 * (-50) / 2 * 2 ;

=> a = 2 * (-25) * 2 ;

=> a = (-50) * 2 ;

=> a = -100;

Step 3: printf("Result=%f", a); It prints the value of variable 'a'.

Hence the output of the program is -100

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

15.What will be the output of the program?


#include<stdio.h>
int main()
{

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

Your Answer: Option (Not Answered)

Correct Answer: Option C

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".

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

16.What will be the output of the program?

#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

Your Answer: Option (Not Answered)

Correct Answer: Option D

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".

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum


https://www.indiabix.com/online-test/c-programming-test/random 9/12
8/10/2018 Test Result

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack overflow.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

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.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

20. What will be the output of the program?


#include<stdio.h>

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

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum

*** END OF THE TEST ***

Feedback
Quality of the Test : -- Select --

Difficulty of the Test : -- Select --


https://www.indiabix.com/online-test/c-programming-test/random 11/12
8/10/2018 Test Result

Comments:
...

Submit Feedback

Current Affairs 2018

Interview Questions and Answers

© 2009 - 2018 by IndiaBIX™ Technologies. All Rights Reserved. | Copyright | Terms of Use & Privacy Policy

Contact us: info-@-@[email protected] Follow us on twitter!

https://www.indiabix.com/online-test/c-programming-test/random 12/12

You might also like