Skip to content

Instantly share code, notes, and snippets.

@ukitazume
Created December 2, 2011 12:16
Show Gist options
  • Save ukitazume/1423039 to your computer and use it in GitHub Desktop.
Save ukitazume/1423039 to your computer and use it in GitHub Desktop.
//
// main.c
// helloworld
//
// Created by kitazume yu on 11/11/24.
// Copyright (c) 2011年 none. All rights reserved.
//
#include <stdio.h>
void line(void);
void char_test(void);
void str_test(void);
void str_stock_test(void);
void line(void)
{
printf("----------------\n");
}
int main (int argc, const char * argv[])
{
char_test();
line();
str_test();
line();
str_stock_test();
return 0;
}
void char_test(void)
{
char c = 'a';
printf("%c\n", c);
printf("%p\n", &c);
}
void str_test(void)
{
char str[] = "abc";
char *p = str;
printf("%s\n", str); // abc
printf("%p\n", p); // 0x7fff5fbff93b
printf("%p\n", &str); // 0x7fff5fbff93b
printf("%c\n", str[0]); // a
printf("%p\n", &str[1]); // 0x7fff5fbff93c
line();
for (int i = 0; str[i] != '\0'; i++) {
printf("%c\n", str[i]);
}
}
void str_stock_test(void)
{
char *str_stack[] = {
"Iaa",
"bbb",
NULL
};
char **q = str_stack;
printf("%s\n", str_stack[0]); // Iaa
printf("%p\n", str_stack); // 0x7fff5fbff910
printf("%p\n", q); // 0x7fff5fbff910
printf("%s\n", *str_stack); // Iaa
printf("%c\n", **str_stack); // I
line();
for (int i = 0; str_stack[i] != NULL; i++) {
printf("%s\n", str_stack[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment