C Syntax and Basics

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM

[rps-include post=6557]

We have successfully compiled our application. But while compiling we have no detailed information about the program. In this chapter we will look basics of C programming language.

Token

The smallest part of a C program is tokens. Compilers start by reading source code and parsing tokens. If there is an unexpected token compile process will stop and give error. From developer point of view tokens are not so important. Below there is an example about tokens.

  • printf
  • (
  • “Hi”
  • )
  • ;

Semicolons

In C semicolons are used as statement terminator. Each statements end with a semicolon. One of the most error causes is missing semicolon. Following code part will generate and semicolon error.

As we see in the screenshot we will get an error like expected ';' ... if we missed the semicolon.

Statement

Statement is smallest part of the C which is meaningful from point of developer.  Statements are delimited with semicolons like below.

This statements prints some text to the standard output

This statement return 0 from a function

This statement will create a variable named age.

If semicolon is not used for a statement it will give error not will not compiled.

Comments

Comments are very important facility of C programming language. Writing program-rams is not just writing code . To write understandable code there should be documentation for yourself and others. These documentation can be done in the source code without effecting the application process. Comments are the way to documents our source code. Comments are not compiled or executed. Below example we can see there is two type of comment.

  • Single line comments wraps only single line and specified with //
  • Multi line comments wraps multiple lines and starts with /* , ends with */

Identifiers

Identifiers are used to set names for variable, functions and user defined items. Identifiers can use letters A to Z, a to z, underscore _ and numbers. But numbers cannot be used as first character in the identifier Here are some acceptable identifiers.

Here are some unaccepted identifiers

Case Sensitive

C is case sensitive language. Which means age is not same with Age . They specify different things. Following example will produce error.

Case Sensitive

Case Sensitive

AGE variable is like undefined.

Keywords

Keywords are reserved words all ready used by C language. For example char is used to define character variables and can not used as variable, function and other user defined items name. Following usage is forbidden by C programming language.

We can not use char as variable name.

C identifier error

Here are keyword used by C.

LEARN MORE  Java - Basics and Comments
auto else long switch
break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double

[rps-include post=6557]

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)