'앎/c_cpp'에 해당되는 글 2건

  1. 2014.02.19 C 연산자 우선순위
  2. 2014.02.18 C 에서 Boolean 타입 사용

C 연산자 우선순위

앎/c_cpp 2014. 2. 19. 01:33 |


 연산 순위

 연산자 

 결합 순서

 1

 ()    []    ->    .

      →

 2

 !    ~    ++    --    -    +    (형명)    *    &    sizeof

  ←    

 3

 *    /    %

      →

 4

 +    -

      →

 5

 <<    >>

      →

 6

 <    <=    >    >=

      →

 7

 ==    !=

      →

 8

 &

      →

 9

 ^

      →

 10

 |

      →

 11

 &&

      →

 12

 ||

      →

 13

 ?   :

 ←   

 14

 =    op=

 ←   

 15

 ,

      →


' > c_cpp' 카테고리의 다른 글

C 에서 Boolean 타입 사용  (0) 2014.02.18
Posted by 후니아부지
:

C99 이전의 C에서는 Boolean 타입이 존재하지 않았다.

따라서 bool 타입을 따로 정의해서 사용했다.

typedef int bool
#define false 0
#define true 1

bool b = false;

C99 에 들어와서는 Boolean 타입을 지원하게 되었다.


stdbool.h 의 내용을 보면 아래와 같다.
#ifndef __cplusplus

#define bool	_Bool
#define true	1
#define false	0

#else /* __cplusplus */

/* Supporting  <stdbool.h> in C++ is a GCC extension.  */
#define _Bool	bool
#define bool	bool
#define false	false
#define true	true

#endif /* __cplusplus */

/* Signal that all the definitions are present.  */
#define __bool_true_false_are_defined	1


위 내용처럼 C나 C++ 에서 모두 bool 타입으로 사용하면 된다.

#include <stdbool.h>

bool b = true;

' > c_cpp' 카테고리의 다른 글

C 연산자 우선순위  (0) 2014.02.19
Posted by 후니아부지
: