C 語言筆記
  • Introduction
  • GCC 編譯器
  • 使用Visual Studio
  • Header Files
    • stat.h
  • 型別
    • 指標
    • 字串
  • 建立 Library
  • Linux kernel
  • Stack pointer、Frame pointer
  • 相關推薦資料
Powered by GitBook
On this page
  • 範例:
  • 結論

Was this helpful?

  1. 型別

字串

char s[] = "Hello World";
char *s  = "Hello World";
  • char s[] 是個char array,含12個byte(包含結尾\0)

  • char *s 是一個 pointer 指向 char,s 指向 "Hello World" 這個string literal的起始記憶體位置

範例:

#include <iostream>
using namespace std;
 int main() {
  char s1[] = "Hello World";
  char *s2  = "Hello World";

  cout << "size of s1: " << sizeof(s1) << endl;
  cout << "size of s2: " << sizeof(s2) << endl;
}

結果為:

size of s1: 12

size of s2: 4

結論

char *s速度較快

Previous指標Next建立 Library

Last updated 5 years ago

Was this helpful?