#

Saturday, July 11, 2020

Grammar of C Programming Language | C Language Tutorial



Communicating with a computer involves speaking the language the computer understands, which immediately rules out English as the language of communication with computers.

However, there is a close analogy between learning the English language and learning C language. The classic method of learning English is to first learn the alphabets used in the language, then learn to combine these alphabets to form words, which in turn, combined to form sentences and sentences are combined to form paragraphs.

Learning C is similar and easier. Instead of straight-away learning how to write programs, we must first know what alphabets, numbers, and special symbols are used in C, then how using them, constants, variables, and keywords are constructed, and finally, how these are combined later on to form a program.



STEPS IN LEARNING C-LANGUAGE
  • The C character set
  • Constants, Variables, and Keywords
  • Instructions
  • Program

The C Character Set

A Character denotes any alphabet, digit, or special symbol used to represent information. Some valid alphabets, numbers, and special symbols allowed in C are-

Programming language, C language


Constants, Variables, and Keywords

The alphabets, digits, and special symbols when properly combined form constants, variables, and keywords. 

A Constant is an entity that doesn't change, whereas, a Variable is an entity that may change. A Keyword is a word that carries special meaning. 

Types of C Constants

C Constants can be divided into two major categories-
  • Primary Constants
  • Secondary Constants

Primary constant is also divided in three categories.
  • Integer Constant
  • Real Constant
  • Character Constant
For constructing these different types of constants, certain rules have been laid down. These rules are for Integer Constant-

  • An Integer constant must have at least one digit.
  • It must not have a decimal point.
  • It can be either positive or negative.
  • if no sign precedes an integer constant, it is assumed to be positive.
  • No commas and blanks are allowed within an Integer Constant
  • The allowable range of integer constants is -2147483648 to +2147483647
NOTE -->  The range of an Integer constant depends upon the compiler.



Rules For Constructing Real Constants

Real constants are often called floating-point constants. The real constant could be written in two forms-
  • Fractional Form
  • Exponential Form

The following rule must be observed while constructing real constants expressed in the fractional form:
  • A real constant must have at least one digit.
  • It must have a decimal point.
  • It could be either negative or positive.
  • The default sign is Positive.
  • No commas or blanks are allowed within a real constant.

The exponential form is usually used if the value of the constant is either too small or too large. Following rules must be observed while constructing real constants expressed in exponential form:

  • The mantissa part and the exponential part should be separated by a letter e or E.
  • The mantissa part may have a positive or negative sign.
  • Default sign of mantissa part is positive
  • The exponent must have at least one digit, which must be a positive or negative integer. The default sign is positive.
  • The range of real constant expressed in exponential form is -3.4e38 to 3.4e38

The following rules are for constructing Character Constants:

  • A character constant is a single alphabet, a single digit, or a single special symbol enclosed within single inverted commas.
  • Both the inverted commas should point to the left.

Types of C Variable

A particular type of variable can hold only the same type of constants. For example, an integer variable can hold only integer constant, a real variable can hold only real constant and so on.

The rules for constructing different types of constants are different, However, for constructing variable names of all types, the same set of rule applies. These rules are the following:

  • A variable name is any combination of alphabets, digits, and underscores.
  • The first character in the variable must be an alphabet or underscore ( _ ).
  • No commas or blanks are allowed within a variable name.
  • No special symbol other than underscore can be used in a variable name.

C Keywords

Keywords are the words whose meaning has already been explained to the C compiler.

There are only 32 keywords available in C language.



No comments:

Post a Comment

Popular Feed

Recent Story

Featured News

Back To Top