변수의 선언과 값의 치환

C : 2007. 11. 1. 13:25
 

변수(variable) - 다양한 값을 저장할 수 있는 이름이 부여된 기억장소.


char (%c) 8비트 하나의 문자를 저장하기 위해 사용.

int (%d) ┌부호가 있는 정수형 16비트 -32,768~32,767

             └윈도우 NT/95 - 32비트 -2,147,648~2,147,647

float/dueble (%f / %lf) - 부호가 있는 실수 4 bytes / 8 bytes



문장의 끝 - 세미콜론(;)

C언어는 영문 대문자와 소문자를 구분한다.


//p.44 예제 1
#include <stdio.h>
int main(void)
{
 int num;   //정수형 선언문
 num=100;
 printf("The value is %d", num);

 return 0;
}

printf 함수 안에 큰 따옴표 내의 문장을 화면에 출력한다.


//p.45 예제 2
#include <stdio.h>
int main(void)
{
 char ch;
 float f;
 double d;

 ch = 'x';             //치환
 f = 100.123;
 d = 123.009;

 printf("ch is %c, ", ch);
 printf("f is %f, ", f);
 printf("d is %f", d);


 return 0;
}

각 값을 선언에 따라 변수 출력.


//p.45 연습문제 2
#include <stdio.h>
int main(void)
{
 int num;

 num = 1000;
    printf("%d is the value of num", num);

 return 0;
}

Posted by 청웨일