Jump to content

Easy Question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
karatara

karatara

    Newbie

  • Members
  • Pip
  • 2 posts
int array[5], i, *ip;
for(i = 0; i < 5; i++) array[i] = i;
ip = array;
printf("%d\n", *(ip + 3 * sizeof(int)));

a.Won't compile
b.3
c.4
d.indeterminate



struct node
{ 
     char a; 
     char b; 
     char c; 
};
struct node s= { 3, 5,6 };
struct node *pt = &s;
printf("%d" , (short)pt);

a.indeterminate
b.1283
c.5
d.3



char *p = "hello, world!";
p[0] = 'H';
printf("%s\n" , p);

a.Hello, World!
b.hello, World!
c.Won't compile
d.Program will crash

Edited by WingedPanther, 26 January 2009 - 04:23 AM.
add code tags (the # button)


#2
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
One thread is enough, do you have the right #include's?

int array[5], i, *ip;
for(i = 0; i < 5; i++) array[i] = i; 
ip = array;
printf("%d\n", *(ip + 3 * sizeof(int)));

You need to maintain whitespace better too imo, because it's hard to read without it. Don't forget code tags!

Pointers aren't my fauté but I can't see where it's wrong, I would assume in the assignments, but also, for such a simple task you don't need pointers..
Posted Image

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Have you tried compiling these (after adding appropriate headers)? For those that compile, have you tried running them? That will answer some of your questions.

code tags added (the # button)... please use them in the future.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
1. d *(ip + 3 * sizeof(int)) , assuming 32 bit machine, is equiv. to *(ip+12), or ip[12], or array[12], the memory might not be accessible, or at the best, its content cannot be easily predicted.

2. a. Depending on byte order of the machine, aka, bigeandian or little endian, either 0x0305, or 0x0503;

3. a.