Loading Test...
Instruction:
Total number of questions : 20 .
Time alloted : 20 minutes.
Each question carry 1 mark, no negative marks.
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");
else if(x > y)
printf("x is greater than y\n");
else if(x < y)
printf("x is less than y\n")
return 0;
}
Answer: Option A
Explanation:
This program will result in error "Statement missing ;"
printf("x is less than y\n") here ; is added to the end of this statement.
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
2.
The modulus operator cannot be used with a long double .
Answer: Option A
Explanation:
fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point or long double divisions.
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
3.
Which of the following correctly shows the hierarchy of arithmetic operations in C?
Answer: Option D
Explanation:
Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction).
How Do I Remember ? BODMAS !
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)
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum
4.
What will be the output of the program?
#include<stdio.h>
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);
}
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;
}
6.
What will be the output of the program ?
#include<stdio.h>
int main()
{
printf(5+"Good Morning\n");
return 0;
}
Answer: Option D
Explanation:
printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.
Hence the output is "Morning"
Learn more problems on : Strings
Discuss about this problem : Discuss in Forum
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);
}
Answer: Option D
Explanation:
Step 1 : void fun(); This is the prototype for the function fun() .
Step 2 : fun(); The function fun() is called here.
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.
The given input characters are "abc"
Output : cba
Learn more problems on : Strings
Discuss about this problem : Discuss in Forum
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;
}
Answer: Option B
Explanation:
This program converts the given string to upper case string.
Output :
Enter a string: indiabix
INDIABIX
Learn more problems on : Strings
Discuss about this problem : Discuss in Forum
9.
What will be the output of the program ?
#include<stdio.h>
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;
}
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;
}
Answer: Option C
Explanation:
The file source.txt contains "Be my friend".
fseek(fs, 0, SEEK_END); moves the file pointer to the end of the file.
fseek(fs, -3L, SEEK_CUR); moves the file pointer backward by 3 characters.
fgets(c, 5, fs); read the file from the current position of the file pointer.
Hence, it contains the last 3 characters of "Be my friend".
Therefore, it prints "end".
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
11.
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;
}
Answer: Option B
Explanation:
Instead of 20 use 20L since
fseek() need a long offset value.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
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>
int main(int argc, char **argv)
{
printf("%s\n", *++argv);
return 0;
}
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>
int main(int argc, char *argv[])
{
int j;
j = argv[1]+argv[2]+arg[3];
printf("%d", j);
return 0;
}
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>
int main(int sizeofargv, char *argv[])
{
while(sizeofargv)
printf("%s", argv[--sizeofargv]);
return 0;
}
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;
}
16.
Point out the error in the program.
#include<stdio.h>
#define MAX 128
int main()
{
char mybuf[] = "India";
char yourbuf[] = "BIX";
char const *ptr = mybuf;
*ptr = 'a';
ptr = yourbuf;
return 0;
}
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".
Learn more problems on : Const
Discuss about this problem : Discuss in Forum
17.
Declare the following statement?
"An array of three pointers to chars".
18.
What do the following declaration signify?
int *f();
19.
What will be the output of the program?
#include<stdio.h>
typedef unsigned long int uli
typedef uli u;
int main()
{
uli a;
u b = -1;
a = -1;
printf("%lu, %lu"a, b);
return 0;
}
20.
Can you use the fprintf() to display the output on the screen?
Answer: Option A
Explanation:
Do like this
fprintf(stdout, "%s %d %f", str, i, a); Learn more problems on : Library Functions
Discuss about this problem : Discuss in Forum
Submit your test now to view the Results and Statistics with answer explanation.
Note:
Click the 'Submit Test' button given in the bottom of this page to Submit your answers.
Test will be submitted automatically if the time expired.
Don't refresh the page.
Marks : [XX/XX]
Total number of questions
:
[TQ]
Number of answered questions
:
[AQ]
Number of unanswered questions
:
[UQ]