Don’t worry, unlock all articles / blogs on PrepInsta by just simply logging in on our website
Type atleast 3 characters
Popular Searches
Trending Pages
Notifications Mark All Read
No New notification
June 23, 2019
Question 1
Function main() { double d = 123.4 static float f =123.4 if (d==f) print ”Both of them are equal” else if( f > d ) print ”Float is greater” else print ”Double is greater” }
Float is greater
Double is greater
Code will generate error
Both of them are equal
Good Job!
Oops!
While d is double and f is float data type, but still we can compare them in the if condition. In the first if condition the f==d is set to be true So, both of them are equal will be printed.
Please login to submit your explanation
Login to see your performance analytics by signing in
Start
Question 2
For
While
Do while
Perforate
Do while is exactly what the questions says for loop does the same thing but not in the exact scenario as the question
Question 3
int p = 1256, q ,r, s=10; q=p/s; r=p-q; print r;
126
1131
125.6
1130.6
1256/10 = 125 1256 - 125 = 1131
Question 4
function foo() { int a = 0; switch(a) { case 0 : print "2"; case 2 : print "2"; case 4 : print "2"; }
nothing gets printed
2
222
222 will be printed as there is no break anywhere
Question 5
function foo() { int a= 245,b=5, d; d = a/b switch(d) { case 4 :print "I behaved correctly" break case 49:print "I behaved with accuracy" break default:print "Not Sure" } }
I behaved correctly
I behaved with accuracy
Not Sure
Error
"Semicolon is missing in the break statement"
Question 6
For Loop
do while
if
Recursion
Only recursion feeds value to it again and again in other loops we have to write code to iterative values with i++ or i= i-2 etc.
Question 7
Integer a = 20, b =10, c = 20, d =10 Print a*b/c-d Print a*b/(c-d) Will the output be same for the two ?
The output will have a difference of 20
Will be same
Cant be said depends on compiler
differ by 100
Print a*b/c-d Print a*b/(c-d) Here the precedence will be followed in the 1st case the The value will be 20*10 =200/20=10 then 10-10=0 In a*b/(c-d) the value will be 200/10 = 20 Hence the answer is (the output will have difference of 20)
Question 8
#include <stdio.h> int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf("%d ", fun(2)); return 0; }
8
16
32
Fun(2) | 2*fun(3) | 2*fun(4) | 4 After tree evaluation we get 16 So, C is the correct answer
Question 9
#include<stdio.h> int main( ) { int a=300,b,c; if(a>=400) b=300; c=200; printf("%d,%d,%d\n",a,b,c); return 0; }
Garbage value, Garbage Value
300,200
200,300
300, Garbage, 200
Question 10
#include<stdio.h> int main( ) { int x=3,y,z; y=x=10; z=x<10; printf("\nx = %d y = %d z = %d", x,y,z); return 0; }
10,10,10
10,10,0
0,0,0
0,10,10
Explanation on a program code: we have a declaration of 3 variables with the int type, that is 3 variables which will save value of an integer number. At once at the declaration x receives value 3. In the second line of the program y and x receive identical value: number 10. In the 3rd line z expression receives result x <10. As x at us it is equal 10, expression 10 <10 will be false, and the result false expression is 0. That is z will receive value 0. The last line we display value of variables through library function of printf. In quotes is a line of a format. Here we specify how to interpret value of variables. \\\\n means word wrapping; x =, y =, z = will be displayed as it is written; %d is a qualifier which specifies that variables which go after a line of a format will be displaid as integer numbers. The result of a program runtime will be such: x = 10 y = 10 z = 0
Please login to report
Login/Signup to comment
Get Hiring Updates right in your inbox from PrepInsta
Login/Signup to comment