一 你真正懂了C語言了嗎?
很多人剛把c語言用了兩年,就以為很懂,等遇到稍微深層次一點的問題,就卡住了。這里,有一個問題,可以考察你對這三者理解如何。
二 一個例子:
#include <stdio.h> typedef unsigned char uint8_t; typedef struct { uint8_t ssid[32]; /**< SSID of ESP8266 soft-AP */ uint8_t password[64]; /**< Password of ESP8266 soft-AP */ } wifi_ap_config_t; typedef struct { uint8_t ssid[32]; /**< SSID of target AP*/ uint8_t password[64]; /**< password of target AP*/ } wifi_sta_config_t; typedef union { wifi_ap_config_t ap; /**< configuration of AP */ wifi_sta_config_t sta; /**< configuration of STA */ } wifi_config_t; #define SSID "test" #define PASSWD "1234567890" int main() { wifi_config_t wifi_config = { .sta = { .ssid = SSID, .password = PASSWD }, }; printf("hello world"); }
在你沒有運行代碼之前,能夠看出來這個例子能夠運行正確嗎?有啥語法問題嗎?
三 拓展問題
1 把這個結構體換成一個從數組中獲取ssid和passwd,這個該怎么解決呢?寫出你的代碼。
2 把這個宏定義換成一個函數指針,從函數指針中獲取ssid和passwd,這個代碼該怎么改呢?寫出你的代碼。
假如你這兩個都弄對了,恭喜你,說明你的c語言基礎還真是不錯的。