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
Point out the error in the program?
#include < stdio.h >int main() { struct bits { float f:2; }bit; printf("%d\n", sizeof(bit)); return0; }
4
2
Error: cannot set bit field for float
Error: Invalid member access in structure
Option C
#include < stdio.h >int main() { struct emp { char name[25]; int age; float bs; }; struct emp e; e.name = "Suresh"; e.age = 25; printf("%s %d\n", e.name, e.age); return0; }
Error: Lvalue required/incompatible types in assignment
Error: invalid constant expression
Error: Rvalue required
No error, Output: Suresh 25
Option A
We cannot assign a string to a struct variable like e.name = "Suresh"; in C. We have to use strcpy(char *dest, const char *source) function to assign a string. Ex: strcpy(e.name, "Suresh");
Assunming, integer is 2 byte, What will be the output of the program?
#include < stdio . h >int main() { printf("%x\n", -1>>1); return0; }
ffff
0fff
0000
fff0
Negative numbers are treated with 2's complement method. 1's complement: Inverting the bits ( all 1s to 0s and all 0s to 1s) 2's complement: Adding 1 to the result of 1's complement. Binary of 1(2byte) : 0000 0000 0000 0001 Representing -1: 1s complement of 1(2byte) : 1111 1111 1111 1110 Adding 1 to 1's comp. result : 1111 1111 1111 1111 Right shift 1bit(-1>>1): 1111 1111 1111 1111 (carry out 1) Hexadecimal : f f f f (Filled with 1s in the left side in the above step) Note: 1. Fill with 1s in the left side for right shift for negative numbers. 2. Fill with 0s in the right side for left shift for negative numbers. 3. Fill with 0s in the left side for right shift for positive numbers. 4. Fill with 0s in the right side for left shift for positive numbers.
If an unsigned int is 2 bytes wide then, What will be the output of the program ?
#include < stdio . h >int main() { unsignedint m = 32; printf("%x\n", ~m); return0; }
ffdf
ddfd
Assuming a integer 2-bytes, What will be the output of the program?
#include < stdio . h >int main() { printf("%x\n", -1<<3); return0; }
fff8
0
-1
Option B
The system will treat negative numbers in 2's complement method. Example: Assume the size of int is 2-bytes(16 bits). The integer value 1 is represented as given below: Binary of 1: 00000000 00000001 (this is for positive value of 1) 1's complement of binary 1: 11111111 11111110 2's complement of binary 1: 11111111 11111111 Thy system will store '11111111 11111111' in memory to represent '-1'. If we do left shift (3 bits) on 11111111 11111111 it will become as given below: 11111111 11111111 ---(left shift 3 times)---> 11111111 11111000. So, 11111111 11111000 ---(binary to hex)---> FF F8. (Required Answer)Note: How is the negative number obtained from 2's complement value? As stated above, -1 is represented as '11111111 11111111' in memory. So, the system will take 2's complement of '11111111 11111111' to the get the original negative value back.Example: Bit Representation of -1: 11111111 11111111 Since the left most bit is 1, it is a negative number. Then the value is 1's complement: 00000000 00000000 2's complement: 00000000 00000001 (Add 1 to the above result) Therefore, '00000000 00000001' = 1 and the sign is negative. Hence the value is -1.
#include < stdio . h >int main() { unsignedint a=0xffff; ~a; printf("%x\n", a); return0; }
00ff
What will be the output of the program?
#include < stdio . h >int main() { unsignedchar i = 0x80; printf("%d\n", i<<1); return0; }
256
100
80
#include < stdio . h >int main() { printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1); return0; }
4 1 8 1
4 >> 1 8 >> 1
2 >> 4 Garbage value >> Garbage valu
2 4
#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; } return0; }
12400
12480
12500
12556
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