Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone tell me which one is correct or most appropriate answer for code written in C language?

Code1:
C
#include<stdio.h>

int main()
{
    int i=10, j=20;
    const int *ptr = &i;

    printf("i = %5X", ptr);
    printf("ptr = %d", *ptr);
    ptr = &j;
    printf("j = %5X", ptr);
    printf("ptr = %d", *ptr);
    return 0;
}

Choice:
A. i= FFE2 ptr=12 j=FFE4 ptr=24
B. i= FFE4 ptr=10 j=FFE2 ptr=20

C. i= FFE0 ptr=20 j=FFE1 ptr=30
D. Garbage value

Code2:
C
#include<stdio.h>

int fun(int **ptr);

int main()
{
    int i=10;
    const int *ptr = &i;

    fun(&ptr);
    return 0;
}


C
int fun(int **ptr)
{
    int j = 223;
    int *temp = &j;

    printf("Before changing ptr = %5x\n", *ptr);
    const *ptr = temp;
    printf("After changing ptr = %5x\n", *ptr);
    return 0;
}


The answer of above program

Because i dont know much about pointers in C
Posted
Updated 9-Jun-10 8:55am
v5
Comments
Richard MacCutchan 9-Jun-10 8:35am    
You said "Thanks Friend but i got the answer". Maybe you could tell the rest of us what the answer is, and also the question.

Why don't you (try to) compile it?
:)
 
Share this answer
 
Comments
YOGESH DHAGE 9-Jun-10 7:11am    
Actully i am in office and i am not having compiler with me and i cant install in my office system and its urgent thats why friend
YOGESH DHAGE wrote:
Can anybody tell me wich one is correct or most apropriate


Correct or most appropriate for what? You have not explained what your code is supposed to do.
 
Share this answer
 
Comments
YOGESH DHAGE 9-Jun-10 7:34am    
Thanks Friend but i got the answer
Thanks very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900