C Programming: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 41: Line 41:
Identifiers are names for entities in a C program, such as variables, arrays, functions, structures, unions and labels. An identifier can be composed only of uppercase, lowercase letters, underscore and digits, but should start only with an alphabet or an underscore.
Identifiers are names for entities in a C program, such as variables, arrays, functions, structures, unions and labels. An identifier can be composed only of uppercase, lowercase letters, underscore and digits, but should start only with an alphabet or an underscore.


'''Rules for Naming Identifiers'''
'''Rules for Naming Identifiers:'''
# An identifier can only have alphanumeric characters (a-z , A-Z , 0-9) (i.e. letters & digits) and underscore( _ ) symbol.
# An identifier can only have alphanumeric characters (a-z , A-Z , 0-9) (i.e. letters & digits) and underscore( _ ) symbol.
# Identifier names must be unique
# Identifier names must be unique
Line 49: Line 49:
# Must not contain white spaces.
# Must not contain white spaces.
# Identifiers are case-sensitive.
# Identifiers are case-sensitive.
'''Kinds of identifiers:'''
# Internal
# External


=== Keywords ===
=== Keywords ===

Revision as of 02:11, 5 February 2018

Overview

C (/siː/, as in the letter c) is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from Supercomputers to Embedded Systems.

C was originally developed by Dennis Ritchie between 1969 and 1973 at Bell Labs, and used to re-implement the Unix Operating System. It has since become one of the most widely used programming languages of all time, with C compilers from various vendors available for the majority of existing computer architectures and operating systems. C has been standardized by the American National Standards Institute (ANSI) since 1989 and subsequently by the International Organization for Standardization (ISO).

C is an imperative procedural language. It was designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory, to provide language constructs that map efficiently to machine instructions, and to require Minimal Run-Time Support. Despite its Low-Level Capabilities, the language was designed to encourage Cross-Platform Programming. A standards-compliant and portably written C program can be compiled for a very wide variety of computer platforms and operating systems with few changes to its source code. The language has become available on a very wide range of platforms, from Embedded Microcontrollers to Supercomputers.


Getting Start

Traditionally it was little bit difficult to programming with C/C++. Have to depends on Turbo C/C++ or Borland C/C++, very much annoying to install and configure them. Where CodeBlocks is blessing for us with 91.3 MB of installer with Zero Configuration needs, also support so many features using plugins. First I hear from one of my colleagues then from one of my tutor and fellows at TechshopBD. A C Program basically consists of the following:

  1. Preprocessor Commands
  2. Functions
  3. Variables
  4. Statements & Expressions
  5. Comments

Hello World

//main.c
#include <stdio.h>

int main()
{
    printf("Hello World!\n");
    return 0;
}

C Tokens

C Supports Six Types of Tokens:

  1. Identifiers
  2. Keywords
  3. Constants
  4. Strings
  5. Operators
  6. Special Symbols

Identifiers

Identifiers are names for entities in a C program, such as variables, arrays, functions, structures, unions and labels. An identifier can be composed only of uppercase, lowercase letters, underscore and digits, but should start only with an alphabet or an underscore.

Rules for Naming Identifiers:

  1. An identifier can only have alphanumeric characters (a-z , A-Z , 0-9) (i.e. letters & digits) and underscore( _ ) symbol.
  2. Identifier names must be unique
  3. The first character must be an alphabet or underscore.
  4. Cannot be keyword as identifiers.
  5. Should not be of length more than 31 characters.
  6. Must not contain white spaces.
  7. Identifiers are case-sensitive.

Kinds of identifiers:

  1. Internal
  2. External

Keywords

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

Exercise

References

Beginning

Intermediate

Advanced

Miscellaneous