璜defineとtypedefの簡単な区別と使用

1904 ワード

/*
 ============================================================================
 Name        : TestDefine.c
 Author      : lf
 Version     :
 Copyright   : Your copyright notice
 Description : #define typedef        

 1          
   #define    ,        ,     .
                    ,        .
   typedef       .        ,  typedef        .
 2        
   typedef                .
   #define      ,              ,       .  :
   #define PI 3.14
             s=PI*r*r    s=3.14*r*r
 3       .
   typedef   ;  ,  #define      ;
                (#)      ; ,  #include <stdio.h>
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
//  #define    NUMBER,   9527
#define NUMBER 9527

void printFun(int i);

//  typedef int   INTEGER
typedef int INTEGER;


//  typedef    .
//   intArray          10
//         :
//typedef <       ><     >[<     >];
typedef int intArray[10];


//  typedef     
typedef struct {
	char name;
	int age;
}student;


//  typedef      
typedef void (*printFunP)(int);

int main(void) {
	testTypedef();
	testDefine();
	return EXIT_SUCCESS;
}

void testTypedef(){
	INTEGER i=5;
	printf("INTEGER i=%d
",i); printf("=============
"); intArray array={1,2,3,4,5,6,7,8,9,0}; int j; for (j = 0; j < 10; j++) { printf("j=%d
",j); } printf("=============
"); student s; s.name='L'; s.age=25; printf("name=%c,age=%d
", s.name, s.age); printf("=============
"); // printFunP printFunPointer; printFunPointer=printFun; (*printFunPointer)(27); //(printFunPointer)(27);// } void printFun(int i){ printf("i=%d
",i); printf("=============
"); } void testDefine(){ printf("number=%d
",NUMBER); }