C Syntax and Basics

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/c-syntax-basics/
PINTEREST
PINTEREST
INSTAGRAM

C Programming Tutorial Index

  1. Introduction To Programming
  2. C Setup Development Environment
  3. C Hello World and Compile First Application
  4. C Syntax and Basics
  5. C Variables
  6. C Numeric Variable Types (Integer, Long, Float)
  7. C String Variables
  8. C Constants and Define Processor
  9. C Operators
  10. C If Else and Switch Case Conditionals
  11. C While Loops
  12. C For Loops
  13. C Arrays
  14. C Functions
  15. C Structure
  16. C Union
  17. C File Operations (Open, Read, Write)
  18. C Pointers
  19. C Type Casting
  20. C Header Files and Include

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.

LEARN MORE  Python Syntax Tutorial

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.

LEARN MORE  Java - Basics and Comments

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.

autoelselongswitch
breakenumregistertypedef
caseexternreturnunion
charfloatshortunsigned
constforsignedvoid
continuegotosizeofvolatile
defaultifstaticwhile
dointstruct_Packed
double

C Programming Tutorial Index

  1. Introduction To Programming
  2. C Setup Development Environment
  3. C Hello World and Compile First Application
  4. C Syntax and Basics
  5. C Variables
  6. C Numeric Variable Types (Integer, Long, Float)
  7. C String Variables
  8. C Constants and Define Processor
  9. C Operators
  10. C If Else and Switch Case Conditionals
  11. C While Loops
  12. C For Loops
  13. C Arrays
  14. C Functions
  15. C Structure
  16. C Union
  17. C File Operations (Open, Read, Write)
  18. C Pointers
  19. C Type Casting
  20. C Header Files and Include
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/c-syntax-basics/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.