C 如何解决这个指针问题?
我想将整数数组的值赋给整数指针。指针接受不同的赋值。请帮我做这个。 我为port_val变量指定了2。但是,将该值分配给ofport_请求变量后,该值就不同了C 如何解决这个指针问题?,c,pointers,C,Pointers,我想将整数数组的值赋给整数指针。指针接受不同的赋值。请帮我做这个。 我为port_val变量指定了2。但是,将该值分配给ofport_请求变量后,该值就不同了 #include <stdio.h> #include <string.h> #include <assert.h> #include <stdlib.h> #include <unistd.h> int main () { printf("INSIDE MAIN..\
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
int main ()
{
printf("INSIDE MAIN..\n");
int64_t of_port[100];
int count=2;
int i;
int port_val = 2;
int port_next_val = 4;
size_t n_ofport_request = 1;
int64_t *ofport_request = malloc(sizeof *ofport_request * (n_ofport_request));
for(i=0;i<count;i++) {
if(i == 0) {
of_port[i] = port_val;
} else {
of_port[i] = port_next_val;
}
ofport_request[0] = of_port[i];
printf("OFPORT VAL = %d\n",ofport_request);
}
return 0;
}
#包括
#包括
#包括
#包括
#包括
int main()
{
printf(“内部主..\n”);
int64_t的_端口[100];
整数计数=2;
int i;
int port_val=2;
int port_next_val=4;
端口请求的大小=1;
端口请求的int64_t*of端口请求=malloc(端口请求的大小*(端口请求的n_));
对于(i=0;i如果要打印指针变量,则必须在变量名称前使用*
使用下面的printf语句即可
printf("OFPORT VAL = %lld\n",*ofport_request);
我不明白为什么端口请求的是一个指针。预期和实际的输出是什么?端口请求的ovsrec接口集(端口请求的常量结构ovsrec接口*行,常量int64*t,端口请求的大小)。我必须将端口请求作为指针传递。例外输出:内部MAIN..ofport VAL=2 ofport VAL=4实际输出:内部MAIN..ofport VAL=7979024 OF PORT VAL=797979024是的,你想说些什么?我没有得到,因为你被删除了。:)仅供参考。UB是什么意思?如何将参数传递给Port_请求函数的ovsrec_interface_set_。@Barathi,您正在使用指针变量。请确保两点。1.如果要使用指针变量值,需要*.2。如果要将其用作pinter(地址),则不使用*。