The greatest mistake you can make in life is to be continually fearing you will make one

Friday 19 February 2010

C Question of the Day 2

1.What is the output of the following program?
#include<stdio.h>>
int main()
{
    int x=100;
    printf("x=%d\nsizeof(x++)=%d\nx=%d\n",x,sizeof(x++),x);
    return 0;
}
Solution
x=100
sizeof(x++)=4
x=100
The x value is not incremented after the x++ operation.because the increment operation performed inside the sizeof operator doesn't change the value of x.
The 'sizeof' operator is used to determine the amount of space anydata-element/datatype occupies in memory


2.What is the output of the following program?
#include<stdio.h>>
int main()
{>
    int x=10;
    printf("x1=%d\n",printf("x2=%d\n",printf("x3=%d\n",x)));
    return 0;
}
Solution

x3=10
x2=6
x1=5
The output function printf returns the number of characters printed.






x=100
sizeof(x++)=4
x=100
The x value is not incremented after the x++ operation.because the increment operation performed inside the sizeof operator doesn't change the value of x.
The 'sizeof' operator is used to determine the amount of space anydata-element/datatype occupies in memory

2 comments: