AmbitionBox
Discover Best Places to work in India
Discover best places to work
Compare & find best workplace
Bring your workplace to life
Highlight your company's perks
Read reviews for 6L+ companies
Rate your former or current company
Discover salaries for 8L+ companies
Calculate your take home salary
Check your market value
Help other jobseekers
Read interviews for 90K+ companies
Interviews questions for 1K+ colleges
Contribute your interview questions
C Programming
What will be output of the following?
#include<stdio.h>int main() { float a=0.7; if(a < 0.7) printf("Cn"); else printf("C++n"); return0; }
C
C++
Error
None of these
Answer : Option A
Explanation :
if(a < 0.7) here a is a float variable and 0.7 is a double constant. The float variable a is less than double constant 0.7. Hence the if condition is satisfied and it prints 'C'
#include<stdio.h>int main() { float a=0.7; printf("%.10f %.10fn",0.7, a); return0; }
Output:0.7000000000 0.6999999881
A float occupies 4 bytes. if the hexadecimal equivalent of each of these bytes is A,B,C and D, then when this float is stored in memory, these bytes get stored in the order
ABCD
DCBA
0xABCD
0xDCBA
Answer : Option B
We want to round off x, a float to an int value. The correct way to do so would be
y=(int)(x+0.5)
y=int(x+0.5)
y=(int)x+0.5
What will be output of the program ?
#include<stdio.h>#include<math.h>int main() { printf("%d, %d, %dn", sizeof(3.14f), sizeof(3.14), sizeof(3.14l)); return0; }
4, 4, 4
4, 8, 8
4, 8, 10
4, 8, 12
Answer : Option CExplanation : sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes.sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.Note: If you run the above program in Linux platform (GCC Compiler) it will give 4, 8, 12 as output. If you run in Windows platform (TurboC Compiler) it will give 4, 8, 10 as output. Because, C is a machine dependent language.
By default any real number is treated as :
a float
a double
a long double
depends on the memory model that you are using
What will be output of the following ?
#include<stdio.h>#include<math.h>int main() { printf("%fn", sqrt(36.0)); return0; }
6.0
6
6.0000
Some absurd result
Answer : Option CExplanation :printf("%fn", sqrt(36.0)); It prints the square root of 36 in the float format(i.e 6.000000).Declaration Syntax: double sqrt(double x) calculates and return the positive square root of the given number.
Binary equivalent of 5.375 is
101.101110111
101.011
101011
none of these
Which error you are likely to get when you run the following program? #include<stdio.h> main() { struct emp { char name[20]; float sal; } struct emp e[10]; int i; for(i=0;i<=9;i++) scanf("%s, %f",e[i].name,&e[i].sal); return 0; }
suspecious pointer conversion
Floating point formats not linked
Cannot use scanf for strutures
Strings cannot be nested inside structures
If the binary equivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what would be the output of the following program? #include<stdio.h> int main() { float a =5.375; char *p; int i; p = (char*)&a; for(i=0;i<=3;i++) printf("%02x", (unsigned char)p[i]); return 0; }
40 AC 00 00
04 CA 00 00
00 00 AC 40
00 00 CA 04
Answer : Option C
Join India’s largest community to research company culture
Are you a student or working professional?
Student/Never worked
I am a student/I have never worked
Working Professional
I am working/I have worked before
What are your preferred job locations?
Popular Cities
Other Cities
Follow your preferred designations/job profiles
Suggestions based on your job profile
vs
Similar Companies