int*a=*b=NULL;
时间: 2024-01-17 13:52:28 浏览: 27
This is not a valid C++ statement.
It appears to be trying to declare two pointers, 'a' and 'b', and initialize them to NULL. However, the syntax is incorrect.
To declare a pointer variable in C++, the '*' symbol should come before the variable name, not before the value being assigned. Additionally, 'a' and 'b' should be separate variables, not dereferencing the same pointer.
Here's a corrected example that declares two separate pointer variables and initializes them to NULL:
```
int* a = NULL;
int* b = NULL;
```
相关问题
int *a = NULL; int *b = "a"; a = b;
This code will not compile because we are trying to assign a string literal (which is a constant array of characters) to a pointer to an integer. The types are incompatible, and the compiler will generate an error. Additionally, even if we change the type of `b` to `int*`, we cannot dereference `b` because it points to a null address. This would result in undefined behavior.
以下代码能不能实现两数交换呢?为什么? int a = 10; int b = 20; int *pa = &a; int *pb = &b; int *pc = NULL; *pc = *pa; *pa = *pb; *pb = *pc; printf("%d %d\n", a, b);
这段代码无法实现两数交换,因为指针变量 `pc` 被赋值为 `NULL`,然后试图通过 `*pc = *pa` 将 `a` 的值赋给 `NULL` 所指向的内存空间,这是错误的操作,会导致程序崩溃。正确的做法是把 `pc` 指向 `a` 或者 `b` 的地址,即 `pc = &a` 或 `pc = &b`,然后再进行交换操作。修正后的代码如下所示:
```
int a = 10;
int b = 20;
int *pa = &a;
int *pb = &b;
int *pc = NULL;
pc = pa;
pa = pb;
pb = pc;
printf("%d %d\n", a, b);
```
输出结果为 `20 10`。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)