AD1

Wednesday, 25 January 2017

What will be the output of the following program


output

in this program we perform math operations on the base addresses of the functions , so the output is compiler dependant 
assume the base address of sub() is 4199876 and add() 4199856 and main() is 4199894
so the output will be 4199914

Tuesday, 24 January 2017

What will be the output of the following code 



Output
var1=0    var2=10    var3=1

Explanation 

Pointers and bitfields

what will be the output of the following code

the code creates compilation error , as you can not create a pointer to bit fields , simply because bit fields may not start at byte boundry

Thursday, 19 January 2017

Swap structure values

Assume that you have a structure defined as follow 
struct two_integers {int n1;int n2;};
and this structure is initialized as follow
struct two_integers x={100,-100}; 
Write a C function that returns the same structure x but n1 and n2 are swapped



Structures

In the following code , assume that the base address of the structure is 2424384 (in decimal form) , what will be the output of the program 

Solution
2424384
2424384
2424388
2424392

Tuesday, 17 January 2017

Sorting 2D array

Assume you have 2D array of integers , int a[3][4]={8,7,6,5,
                                                                                                            -2,800,19,-40,
                                                                                                             1,-23,600,-500};

Write a C program to sort it in ascending order (from low to high)

Solution

Monday, 16 January 2017

Increment all array values using pointers

Write C function INC(int array[5],int n) that accepts two parameters array of five integers and integer, and adds the integer n to all array elements , then it returns the new array , as example if array[5]={1,5,7,0,2} and n =5 after function call we have  array[]={6,10,12,5,7}






Saturday, 14 January 2017

Pointers and 2D arrays

Assume you have 2D array S[2][4]={{1234,56},
{1212,33},
{1434,80},
{1312,78}};
write a C program to print all the values and their corresponding addresses of this array
using pointers

Pointer Arithmetic

What will be the output of the following program 



2424388
2424392
2424428
2424416

size of double data type

Write a program to calculate the size of a double data type in terms of Bytes , Do not use the sizeof() operator

Solution