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


Wednesday 11 January 2017

what will be the output of the following program


output will be garbage values
uninitialized array elements have garbage values

Tuesday 10 January 2017

What will be the output of the following program



j=12
k=49

From C file to exe file

Describe in detail how a C program is compiled and executed 

Answer

1) The preprocessor code searches for preprocessor directives (mainly #include or #define) and substitute them with their codes,the output of this step creates an expanded file (.I file)
2) the compiler takes .I file and coverts the high level code into assembly then into machine language (binary format) and generate .obj file
3) the linker takes .obj file and link it with C standard library functions in your code 
and generates the executable version of your C code



Monday 9 January 2017

what will be the output of the following program


x=4.5
y=14.8

What will be the output of the following program


output is
count=4
count=3
count=2
count=1
count=0

Wednesday 4 January 2017

what is the output of the following program


output=110 
by default C functions return int values in case you did not specify the return type

what is the output of the following program


10
10
garbage value
if your function does not return any value , it must be declared as void