1. Introduction to "C" language

    C programming is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language.

Facts about C

  • C was invented to write an operating system called UNIX.
  • C is a successor of B language which was introduced around the early 1970s.
  • The language was formalized in 1988 by the American National Standard Institute (ANSI).
  • The UNIX OS was totally written in C.
  • Today C is the most widely used and popular System Programming Language.
  • Most of the state-of-the-art software have been implemented using C.
  • Today's most popular Linux OS and RDBMS MySQL have been written in C.

Why use C?

C was initially used for system development work, particularly the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as the code written in assembly language. 

Tokens in C

A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. 

Identifiers

A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters, underscores, and digits (0 to 9).C does not allow punctuation characters such as @, $, and % within identifiers. C is a case-sensitive programming language.

examples:- abc, _xyz, hjTkk, x_89, myname50,etc...


Data Type

Data types define the type of data a variable can hold, for example an integer variable can hold integer data, a character type variable can hold character data etc.

There are two types of data type:-

i) Basic data type:-These are fundamental data types in C namely integer(int), floating point(float), character(char) .

Following are the examples of basic data types used in C:

  • char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.
  • int: As the name suggests, an int variable is used to store an integer.
  • float: It is used to store decimal numbers (numbers with floating point value) with single precision.
ii) Derived Data Types

Data types that are derived from fundamental data types are derived types. For example: arrays, pointers, function types, structures, etc.

Basic types

Here's a table containing commonly used types in C programming for quick access.

TypeSize (bytes)Format Specifier
int2%d, %i
char1%c
float4%f


Variable in C
variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times.
Example of declaring of variable:-
int a;
float b;
char c;
Rules for defining variables
  • A variable can have alphabets, digits, and underscore.
  • A variable name can start with the alphabet, and underscore only. It can't start with a digit.
  • No whitespace is allowed within the variable name.
  • A variable name must not be any reserved word or keyword, e.g. int, float, etc.
Keywords in C

In C, we have 32 keywords, which have their predefined meaning and cannot be used as a variable name. These words are also known as “reserved words”. It is good practice to avoid using these keywords as variable name. These are –
  1. Auto            12. Break          23. Struct
  2. For              13. Case            24. Switch
  3. Goto           14. Char            25. Typeof
  4. If                 15. Const          26. Union
  5. Int               16. Continue    27. Unsigned
  6. Long           17. Default       28. Void
  7. Register      18. Double       29. Volatile
  8. Return        19. Enum          30. While
  9. Short          20. Extern         31. Do
  10. Signed       21. Float           32. Else
  11. Sizeof        22. Static
Comments in C:-

Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below −

/* Hello Friends*/

// is also used for single line comments.


Post a Comment

0 Comments