AD1

Tuesday, 25 April 2017

Find the output of the following code


Output
lvalue required as increment operand

Explanation
after reading the code for the first time you may get tricked and say the output will be
c 
c++
python
java 
but this not the output , because you will get compiler error in line 6 when you try to modify the base address of an array which is already a constant pointer

Find the output of the following code



Output 
linker error (undefined symbol x)

Explanation 
extern keyword tells the compiler that the value of the variable x is not in this scope so the compiler does not know variable x memory location so he will not assign x memory location , otherwise during linking time if x is defined in another scope or file , its value will be printed

Find the output of the following code



Output

h h 
e e
l l
l l
o o

Explanation
message[i]=i[message]
because compilers convert message[i] into *(message+i)
where message is the array base address ,also i[message] is converted into
 *(i+message)
so the two expressions are the same

Tuesday, 4 April 2017

Big endian VS little endian

Write a C program to check if your processor is big endian or little endian 

solution

Monday, 13 March 2017

Reverse bits of Byte

write a C function to reverse the bits of a Byte as example if we have variable unsigned char x=0x07=0b00000111 as input parameter after reversing its bits it would return 11100000

solution 


Tuesday, 7 March 2017

Palindrome String

Write a C code to check a String is palindrome or not , Some palindrome strings examples are "a", dad", "radar", "madam", "abcba" etc.

solution



Monday, 6 March 2017

From decimal to binary

Write a C program to convert an integer from decimal to binary , using logical bitwise operators

solution



Thursday, 2 March 2017

what is the output

what is the output of this C code 
output:
66    B
4
Explanation:
union temp t={66,'A'};
this statement will initialize only the first member of the union x with 66 and the compiler will ignore the second value 'A', as one element is sufficient to initialize all union members as they share the same memory locations
sizeof(t) =4 size of largest element in memory location



Wednesday, 1 March 2017

what is the output of this C code

output :
compilation error in line 19 , as you can not assign two structures of different types
also there is a compilation error in line 21 as rational operators can not be applied on structures