No, I am not a novice in c - not at all! I have plenty of experience in c, c++, java etc. But I am facing a awkward problem in c (gcc in RHEL) - I am not able to get the value pointed by the pointer
Look at the following code -
Code:
#include <stdio.h>
int main()
{
int i=100;
int arr[2][3];
arr[1][2]=&i;
printf("a=%d\n",arr[1][2]); -> giving the address
printf("b=%d\n",*(int *)(arr[1][2])); -> giving memory fault
}
Are you running on a 64-bit system, or an embedded system? Either way, you cannot assume that a pointer will fit into an int. Either make your arr be an array of int pointers, or #include stdint.h and make it an array of type intptr_t.
If you still get the same problem, look at (or post) the output of this program:
Code:
#include <stdio.h>
int main()
{
int i = 100;
int arr[2][3];
arr[1][2] = &i;
printf("address: %p\n", &i);
printf("value: 0x%x\n", arr[1][2]);
}
No, I am not a novice in c - not at all! I have plenty of experience in c, c++, java etc...
If you arent a novice in c then you should read up on pointers because arr[1][2] is not a pointer variable...meaning you cant assign an int to an int*.
The result is undefined, and you just might get a segfault as a result if you then try to dereference the non-pointer that results..
No I dont think there should be any runtime errors since i is a local variable and its address would be within the address space of the executing process.
Quote:
Originally Posted by nsinha
How I can get the value? I am really clueless...
Can you post any warnings you get when you compile this program.
You can assign an int* to an int since both are integer types. But you must be aware that an int may be smaller than an int* in your plataform (i.e, sizeof(int) < sizeof(int*) ). If this is the case, the value will be truncated and you probably will end up with an invalid pointer.
I'm sure a long is enough to fit any pointer type on your platform. So, just change the arr type from int to long and you will get wat you want:
Code:
#include <stdio.h>
int main()
{
int i=100;
long arr[2][3];
arr[1][2]=&i;
printf("a=%p\n",(int*) arr[1][2]);
printf("b=%d\n",*(int *)(arr[1][2])); /* will print 100 */
}
four interfaces with ifconfig
all interfaces have the same mac. If is not set for unique.
but it still works.
what difference does it make to have all macs the same or different? (4 Replies)
Hi there
I lost connectivity to one of our remote systems and when I checked the messages log I found the following:
Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s
Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1
Aug 16 13:20:51 host... (9 Replies)
Hi guys,
I got one problem which I definetily no idea.
What would the physical address be for virtual address?
1) 2ABC
2) 3F4B
Here is the page table:see attached
Thank you sos sososososso much!! (0 Replies)
I have following message in my messages file on solaris 10
WARNING: e1000g3712000:3 has duplicate address 010.022.196.011 (in use by 00:50:56:85:25:ef); disabled
Now is there any way i can find which server has 00:50:56:85:25:ef mac address either IP or Hostname ? (6 Replies)
:) Firstly Hi all!!, im NEW!! and on here hoping that someone might be able to offer me some help... i have a server that keeps crashing every few days with the error message:
PANIC KERNAL-MODE ADDRESS FAULT ON USER ADDRESS 0X14
KERNAL PAGE FAULT FROM (CS:EIP)=(100:EF71B5BD)
EAX=EF822000... (10 Replies)
Trying to do a ksh script that needs to list all ip address between ip address a and b ..
ie.
Ip address A=192.168.1.200
Ip address B=192.168.2.15
So the subnet changes from 1 to 2 but I want to list all possible ip addresses between the 2..
Which would be:
192.168.1.200... (4 Replies)
Hi sir,
i want to make such programe which takes MAC(Ethernet) address of any host & give me its IP address.......
but i'm nt getting that how i can pass the MAC address to Frame........
Please give me an idea for making such program...
Thanks & regards
Krishna (3 Replies)
say I have a IP address which is 10.0.0.12, and subnet mask is 255.255.255.240, what is the network address and what is the broadcast address which host lives on?
And could you explain how to get the answer?
thanx in advance! (7 Replies)