int a=10;char * ptr = &a;这样的代码对吗,为什么
时间: 2024-05-21 22:11:10 浏览: 17
This code is incomplete and cannot be executed. It appears that the programmer has declared an integer variable 'a' and a pointer variable 'ptr' that is expected to store the memory address of a character variable. However, the pointer variable is not assigned a value and the character variable is not declared. The code should be completed with appropriate data types and values to be able to compile and run.
相关问题
#include <stdio.h> #include <string.h> #include <stdlib.h> char* reverse(char* s) { int i = strlen(s); int j = i; char* ptr = (char*)malloc(strlen(s) * sizeof(char)); memset(ptr, 0, strlen(s) * sizeof(char)); i--; for (; i >= 0; i--) { ptr[i] = *s; s++; } ptr[j] = '\0'; s = ptr; return s; } void* obfuscate(void* ptr) { int* p = (int*)ptr; *p = (*p ^ 0xdeadbeef) + 0x1337; return ptr; } int main() { char* str = (char*)malloc(200 * sizeof(char)); printf("Enter a string: "); scanf("%s", str); str = (char*)obfuscate((void*)reverse(obfuscate((void*)str)))); printf("Reversed string: %s\n", str); free(str); return 0; } 整理这个代码格式,使其美观容易阅读
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* reverse(char* s) {
int i = strlen(s);
int j = i;
char* ptr = (char*) malloc(strlen(s) * sizeof(char));
memset(ptr, 0, strlen(s) * sizeof(char));
i--;
for (; i >= 0; i--) {
ptr[i] = *s;
s++;
}
ptr[j] = '\0';
s = ptr;
return s;
}
void* obfuscate(void* ptr) {
int* p = (int*) ptr;
*p = (*p ^ 0xdeadbeef) + 0x1337;
return ptr;
}
int main() {
char* str = (char*) malloc(200 * sizeof(char));
printf("Enter a string: ");
scanf("%s", str);
str = (char*) obfuscate((void*) reverse(obfuscate((void*) str)));
printf("Reversed string: %s\n", str);
free(str);
return 0;
}
#include<stdio.h> #include<string.h> #include<stdlib.h> char* reverse(char *s) { int i=strlen(s); int j= i; char *ptr=(char*)malloc(strlen(s)*sizeof(char)); memset(ptr, 0, strlen(s)*sizeof(char)); i--; for(;i>=0 ;i-- ){ ptr[i] = *s; s++; } ptr[j] = '\0'; s=ptr; return s; } int main(){ char *str=(char*)malloc( 200*sizeof(char) ); scanf("%s", str); str = reverse(str); printf("%s", str); return 0; } 修改这个代码让这个代码变得很复杂,难以读懂
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* reverse(char* s) {
int i = strlen(s);
int j = i;
char* ptr = (char*)malloc(strlen(s) * sizeof(char));
memset(ptr, 0, strlen(s) * sizeof(char));
i--;
for (; i >= 0; i--) {
ptr[i] = *s;
s++;
}
ptr[j] = '\0';
s = ptr;
return s;
}
void* obfuscate(void* ptr) {
int* p = (int*)ptr;
*p = (*p ^ 0xdeadbeef) + 0x1337;
return ptr;
}
int main() {
char* str = (char*)malloc(200 * sizeof(char));
printf("Enter a string: ");
scanf("%s", str);
str = (char*)obfuscate((void*)reverse(obfuscate((void*)str))));
printf("Reversed string: %s\n", str);
free(str);
return 0;
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)