retagged by
457 views
1 votes
1 votes
consider the following program

main()

{

int a=5;

int*b=&a;

printf("%p",b);//  .................LINE 1

printf("%d",b);//...................LINE 2

printf("%u",b);//...................LINE 3

}

which of the following statement is true.

A) both Line 1 and line 2  will always print correct address.

B)only line 3 will  always print correct address.

C)only line 1 and 3 will always print correct address.

D)all the lines i.e line 1 line 2 line 3  will always print  correct address.
retagged by

1 Answer

0 votes
0 votes

Answer is (d).

All the lines will print the correct address that is the value of variable b(which is equal to address of  a since its a  pointer), just with different formats. Line one will print the b as a pointer (a hexadecimal value) and line two will print the address represented as integers (%d for decimal representation of integer number and %u for unsigned integer).

Supplementary:

Source: https://www.le.ac.uk/users/rjm1/cotter/page_30.htm

The % Format Specifiers

The % specifiers that you can use in ANSI C are:

Usual variable type Display

%c char single character

%d (%i) int signed integer

%e (%E) float or double exponential format

%f float or double signed decimal

%g (%G) float or double use %f or %e as required

%o int unsigned octal value

%p pointer address stored in pointer

%s array of char sequence of characters

%u int unsigned decimal

%x (%X) int unsigned hex value

Related questions

0 votes
0 votes
2 answers
1
eyeamgj asked Nov 27, 2017
290 views
consider the following declarations1.int a[5]={1,2,3,4,5};2.int *p=(int*) malloc(sizeof(int)*5);which is truea.statement 1 take less tym than statement 2 for execution.b....
0 votes
0 votes
1 answer
2
eyeamgj asked Nov 22, 2017
3,530 views
The output of statement printf ("%d", 10 ? 0 ? 5 : 11 : 12 ) ;
4 votes
4 votes
2 answers
3
sumit goyal 1 asked Aug 9, 2017
3,596 views
int sum(int A[], int n) { int sum = 0, i; for(i = 0; i < n; i++) sum = sum + A[i]; return sum; }
0 votes
0 votes
1 answer
4
Tankut asked Apr 4
71 views
A non empty set A is termed as an algebraic structure ________a)with respect to binary operation *b)with respect to ternary operation ?c)with respect to binary operation ...