int a=250; The variable a is declared as an integer type and initialized to value 250. printf("%1d
", a); It prints the value of variable a. Hence the output of the program is 250.
The sizeof function return the given variable. Example: float a=10; sizeof(a) is 4 bytes
Step 1: float arr[] = {12.4, 2.3, 4.5, 6.7}; The variable arr is declared as an floating point array and it is initialized with the values. Step 2: printf("%d
", sizeof(arr)/sizeof(arr[0])); The variable arr has 4 elements. The size of the float variable is 4 bytes. Hence 4 elements x 4 bytes = 16 bytes sizeof(arr[0]) is 4 bytes Hence 16/4 is 4 bytes Hence the output of the program is '4'.
Q. No. :
5
Question :
What is the output of the following program segment?
void max(int x, int y, int m)
{ if(x>5) m=x;
else m=y;}
int main()
{
int i=20, j=5, k=0;
max(i,j,k);
printf("%d",k);
}
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.
Step 1: char str1[] = "Hello"; The variable str1 is declared as an array of characters and initialized with a string "Hello".
Step 2: char str2[] = "Hello"; The variable str2 is declared as an array of characters and initialized with a string "Hello". We have use strcmp(s1,s2) function to compare strings.
Step 3: if(str1 == str2) here the address of str1 and str2 are compared. The address of both variable is not same. Hence the if condition is failed.
Step 4: At the else part it prints "Unequal".
Q. No. :
9
Question :
Which of the following statements are correct about the program below?
The scope of variable 'j' is the single printf that follows it. So, the last statement that involves 'j' will complain about the undeclared identifier 'j'
#include< stdio.h >
int check (int, int);
int main()
{
int c;
c = check(10, 20);
printf("c=%d
", c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(*p): return(*q);
}
Step 1: int fun(int); Here we declare the prototype of the function fun().
Step 2: int i = fun(10); The variable i is declared as an integer type and the result of the fun(10) will be stored in the variable i.
Step 3: int fun(int i){ return (i++); } Inside the fun() we are returning a value return(i++). It returns 10. because i++ is the post-increment operator.
Step 4: Then the control back to the main function and the value 10 is assigned to variable i.
Step 5: printf("%d
", --i); Here --i denoted pre-increment. Hence it prints the value 9.
Step 1: int no=5; The variable no is declared as integer type and initialized to 5.
Step 2: reverse(no); becomes reverse(5); It calls the function reverse() with '5' as parameter.
The function reverse accept an integer number 5 and it returns '0'(zero) if(5 == 0) if the given number is '0'(zero) or else printf("%d,", no); it prints that number 5 and calls the function reverse(5);. The function runs infinetely because the there is a post-increment operator is used. So, it calls reverse(5) infinitely. loops
Q. No. :
17
Question :
Assume integer is 2 bytes wide. How many bytes will be allocated for the following code?
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.
Q. No. :
20
Question :
Which of the following function is correct that finds the length of a string?
Step 1: void swap(char *, char *); This prototype tells the compiler that the function swap accept two strings as arguments and it does not return anything.
Step 2: char *pstr[2] = {"Hello", "GPLgtests"}; The variable pstr is declared as an pointer to the array of strings. It is initialized to pstr[0] = "Hello", pstr[1] = "GPLgtests"
Step 3: swap(pstr[0], pstr[1]); The swap function is called by "call by value". Hence it does not affect the output of the program.
If the swap function is "called by reference" it will affect the variable pstr.
Step 4: printf("%s
%s", pstr[0], pstr[1]); It prints the value of pstr[0] and pstr[1].
Hence the output of the program is : Hello GPLgtests
Q. No. :
23
Question :
The following code fragment
int x,y = 2,z,a;
x = (y *= 2) + (z = a = y);
printf("%d",x);
A :
prints 8
B :
prints 6
C :
prints 6 or 8 d3epending on the compiler implementation