1. The first question is an input judgment, in which the Classl code is used, something related to the address
#include<stdio.h> #include<string.h> struct A{ long a; int b; }; int main(){ struct A num ={0x6e694c756f796978}; char ch='0'; for(int i=0;ch;i++){ ch=*((char *)&num+i); printf("%c",ch); } printf("\n"); return 0; }
I made a modification to judge whether it will be reversed (similar to this year's question). If there is no result, it means that it is normal positive order input, and the ASClL code of characters is input
2. Rewrite the program and use more methods to change b without changing const
#include<stdio.h> int main(){ const int b=10; /* */ return 0; }
#include <stdio.h> int main() { const int a = 10; int *p =(int *) &a; (*p)++; printf("%d\n", a); return 0; }
If the pointer itself is a constant, it cannot be modified, and the content pointed to by the pointer is a constant and cannot be modified.
Then I can change the address of its address. Here, pay attention to type conversion when assigning the address of a to the pointer, otherwise an error will be reported.
That is, it may be said that the initialization lost the qualification of the pointer target type
3.
struct node { *(int*)((char*)a+2*sizeof(structn))=100; }; struct n{ char a; int b; }; intmain(intargc,char*argv[]){ struct node a[2]={{1,2,3},{4,5,6}}; *(int *)((char *)a+2*sizeof(struct n))=100; return 0; }
The program has two structural variables, struct node a[2] = {{1,2,3},{4,5,6}}; This sentence defines a structure array, generates 48 bytes of space in the next sentence, and then modifies the a after 32 bits to change it, so
The last bit in a changes to {{1, 2, 3}, {4, 5100}}
4.j explain the problem of function call
#include<stdio.h> #define f(a,b) a##b #define g(a) #a #define h(a) g(a) int main(int argc, char* argv[]) { printf("%s\n", h(f(1,2))); printf("%s\n", g(f(1,2))); return 0; }
The important thing of this program is to start defining three macros, namely
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
Here, through analysis, we can get that the first is to change the existence similar to f(a,b) in the later stage into the form of ab. the second is to define an existence such as G (a), release the data as long as it is encountered, and finally define two functions g (a) and H (a). It can also be obtained that in the first output, the external is not g (a), so the internal output will be. At the same time, because ## of the existence, all symbols in it will be deleted, and only 12 will be output. In the second printf, the first is the same, but the external is g (x), so a modification will be made to output according to the format, so f (1,2) will be obtained
5.
#include <stdio.h> #include<string.h> void reserveworld(char* str,int s,int e) { while (s < e) { char c = str[s]; str[s] = str[e]; str[e] = c; s++; e--; } } void reserve(char *str,int n) { int t = 0; for (int i = 0; i <= n; i++) { if (str[i] == ' ' || str[i] == '\0') { reserveworld(str, t, i - 1); t = i + 1; } } } int main() { char str[100] = ""; gets(str); reserveworld(str, 0, strlen(str)-1); reserve(str, strlen(str)); printf("%s", str); return 0; }