<< Chapter < Page Chapter >> Page >
Học xong chương này, sinh viên sẽ nắm được các vấn đề sau: - Bộ chữ viết trong C.- Các từ khóa. - Danh biểu.- Các kiểu dữ liệu - Biến và các biểu thức trong C.- Cấu trúc của một chương trình viết bằng ngôn ngữ lập trình C

Bộ chữ viết trong c

Bộ chữ viết trong ngôn ngữ C bao gồm những ký tự, ký hiệu sau: (phân biệt chữ in hoa và in thường):

  • 26 chữ cái latinh lớn A,B,C...Z
  • 26 chữ cái latinh nhỏ a,b,c ...z.
  • 10 chữ số thập phân 0,1,2...9.
  • Các ký hiệu toán học: +, -, *, /, =,<,>, (, )
  • Các ký hiệu đặc biệt: :. , ; " ' _ @ # $ ! ^ [ ] { } ...
  • Dấu cách hay khoảng trống.

Các từ khoá trong c

Từ khóa là các từ dành riêng (reserved words) của C mà người lập trình có thể sử dụng nó trong chương trình tùy theo ý nghĩa của từng từ. Ta không được dùng từ khóa để đặt cho các tên của riêng mình. Các từ khóa của Turbo C 3.0 bao gồm:

asm auto break case cdecl char

class const continue _cs default delete

do double _ds else enum _es

extern _export far _fastcall float for

friend goto huge if inline int

interrupt _loadds long near new operator

pascal private protected public register return

_saveregs _seg short signed sizeof _ss

static struct switch template this typedef

union unsigned virtual void volatile while

Cặp dấu ghi chú thích

Khi viết chương trình đôi lúc ta cần phải có vài lời ghi chú về 1 đoạn chương trình nào đó để dễ nhớ và dễ điều chỉnh sau này; nhất là phần nội dung ghi chú phải không thuộc về chương trình (khi biên dịch phần này bị bỏ qua). Trong ngôn ngữ lập trình C, nội dung chú thích phải được viết trong cặp dấu /* và */.

Ví dụ :

#include<stdio.h>

#include<conio.h>

int main ()

{

char ten[50]; /* khai bao bien ten kieu char 50 ky tu */

/*Xuat chuoi ra man hinh*/

printf(“Xin cho biet ten cua ban !”);

scanf(“%s”,ten); /*Doc vao 1 chuoi la ten cua ban*/

printf(“Xin chao ban %s\n ”,ten);

printf(“Chao mung ban den voi Ngon ngu lap trinh C”);

/*Dung chuong trinh, cho go phim*/

getch();

return 0;

}

Các kiểu dữ liệu sơ cấp chuẩn trong c

Các kiểu dữ liệu sơ cấp chuẩn trong C có thể được chia làm 2 dạng : kiểu số nguyên, kiểu số thực.

Kiểu số nguyên

Kiểu số nguyên là kiểu dữ liệu dùng để lưu các giá trị nguyên hay còn gọi là kiểu đếm được. Kiểu số nguyên trong C được chia thành các kiểu dữ liệu con, mỗi kiểu có một miền giá trị khác nhau

Kiểu số nguyên 1 byte (8 bits)

Kiểu số nguyên một byte gồm có 2 kiểu sau:

STT Kiểu dữ liệu Miền giá trị (Domain)
1 unsigned char Từ 0 đến 255 (tương đương 256 ký tự trong bảng mã ASCII)
2 char Từ -128 đến 127

Kiểu unsigned char: lưu các số nguyên dương từ 0 đến 255.

=>Để khai báo một biến là kiểu ký tự thì ta khai báo biến kiểu unsigned char. Mỗi số trong miền giá trị của kiểu unsigned char tương ứng với một ký tự trong bảng mã ASCII .

Kiểu char: lưu các số nguyên từ -128 đến 127. Kiểu char sử dụng bit trái nhất để làm bit dấu.

=>Nếu gán giá trị>127 cho biến kiểu char thì giá trị của biến này có thể là số âm (?).

Kiểu số nguyên 2 bytes (16 bits)

Kiểu số nguyên 2 bytes gồm có 4 kiểu sau:

STT Kiểu dữ liệu Miền giá trị (Domain)
1 enum Từ -32,768 đến 32,767
2 unsigned int Từ 0 đến 65,535
3 short int Từ -32,768 đến 32,767
4 int Từ -32,768 đến 32,767

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Lập trình và ngôn ngữ lập trình. OpenStax CNX. Aug 06, 2009 Download for free at http://cnx.org/content/col10886/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Lập trình và ngôn ngữ lập trình' conversation and receive update notifications?

Ask