The simplest way is, use bitwise ‘&’ operator on each bit of number by shifting right one by one and
Tag: C questions
C questions for exam preparation, campus interview preparation and C skills/knowledge build up.
Q39 How to check a particular bit is set or not? Write a program to count number of bits set in an integer.
There are many methods to check a particular bit is set or not. Method 1: Suppose I want to check
Q38 What is storage class and its type?
To know the answer please click on this link C Storage class.
Q37 How will you determine a machine is 32 bit or 64 bit?
All compiler keep the size of integer the same as the size of register on a particular architecture. So the
Q36 Is float a = 22/7 and double b = 22/7 is equal? How to compare floating point numbers?
if(a == b) may be true or may not be, that’s because of the way floating point numbers are stored.
Q34 Write a program to convert from one Endian to another.
int endian_reverse_fun(int num) { int byte0, byte1, byte2, byte3; byte0 = (num & x000000FF) >> 0 ; byte1 = (num
Q33 What is little endian and big endian? How to check a system is little endian or big endian?
Little and big endian are method of storing data in machine. Little Endian means that the lower order byte of
Q32 What is meaning of error that shows lvalue required?
An lvalue is something that can appear on the left side of an assignment, in other words something that can
Q30 When sizeof() operator works, compile time or run time?
sizeof() is a compile time operator. It works at compile time that’s why we called it operator not function. To
Q28 How to check that the stack grows up or down?
To check stack grows up or down take two local variable and check their address. If (address of variable 1
Q27 Write a C program to round numbers.
Use this statement to round numbers (int)(number < 0 ? (number – 0.5) : (number + 0.5))
Q26 Write a C program to check leap year.
#include<stdio.h> int main() { int year; printf(“Enter any year to check leap year\n”); scanf(“%d”,&year); if((year %