WHAT IS CHARACTER CONSTANT IN C PROGRAMMING LANGUAGE

What is c programming language

C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie and Bell Labs, and remains very widely used and influential. By design, C’s features cleanly reflect the capabilities of the targetted CPUs

C is a general-purpose programming language that is extremely popular, simple, and flexible to use. It is a structured programming language that is machine-independent and extensively used to write various applications, Operating Systems like Windows, and many other complex programs like Oracle database, Git, Python interpreter, and more.

It is said that ‘C’ is a god’s programming language. One can say, C is a base for the programming. If you know ‘C,’ you can easily grasp the knowledge of the other programming languages that uses the concept of ‘C’

It is essential to have a background in computer memory mechanisms because it is an important aspect when dealing with the C programming language.

History of C language

The base or father of programming languages is ‘ALGOL.’ It was first introduced in 1960. ‘ALGOL’ was used on a large basis in European countries. ‘ALGOL’ introduced the concept of structured programming to the developer community. In 1967, a new computer programming language was announced called as ‘BCPL’ which stands for Basic Combined Programming Language. BCPL was designed and developed by Martin Richards, especially for writing system software. This was the era of programming languages. Just after three years, in 1970 a new programming language called ‘B’ was introduced by Ken Thompson that contained multiple features of ‘BCPL.’ This programming language was created using UNIX operating system at AT&T and Bell Laboratories. Both the ‘BCPL’ and ‘B’ were system programming languages.

In 1972, a great computer scientist Dennis Ritchie created a new programming language called ‘C’ at the Bell Laboratories. It was created from ‘ALGOL’, ‘BCPL’ and ‘B’ programming languages. ‘C’ programming language contains all the features of these languages and many more additional concepts that make it unique from other languages.

‘C’ is a powerful programming language which is strongly associated with the UNIX operating system. Even most of the UNIX operating system is coded in ‘C’. Initially ‘C’ programming was limited to the UNIX operating system, but as it started spreading around the world, it became commercial, and many compilers were released for cross-platform systems. Today ‘C’ runs under a variety of operating systems and hardware platforms. As it started evolving many different versions of the language were released. At times it became difficult for the developers to keep up with the latest version as the systems were running under the older versions. To assure that ‘C’ language will remain standard, American National Standards Institute (ANSI) defined a commercial standard for ‘C’ language in 1989. Later, it was approved by the International Standards Organization (ISO) in 1990. ‘C’ programming language is also called as ‘ANSI C’.

How C Programming Language Works?

C is a compiled language. A compiler is a special tool that compiles the program and converts it into the object file which is machine readable. After the compilation process, the linker will combine different object files and creates a single executable file to run the program. The following diagram shows the execution of a ‘C’ program

012419 1229 WhatisCProg4

Nowadays, various compilers are available online, and you can use any of those compilers. The functionality will never differ and most of the compilers will provide the features required to execute both ‘C’ and ‘C++’ programs.

Following is the list of popular compilers available online:

  • Clang compiler
  • MinGW compiler (Minimalist GNU for Windows)
  • Portable ‘C’ compiler
  • Turbo C

Where is C used? Key Applications

  1. ‘C’ language is widely used in embedded systems.
  2. It is used for developing system applications.
  3. It is widely used for developing desktop applications.
  4. Most of the applications by Adobe are developed using ‘C’ programming language.
  5. It is used for developing browsers and their extensions. Google’s Chromium is built using ‘C’ programming language.
  6. It is used to develop databases. MySQL is the most popular database software which is built using ‘C’.
  7. It is used in developing an operating system. Operating systems such as Apple’s OS X, Microsoft’s Windows, and Symbian are developed using ‘C’ language. It is used for developing desktop as well as mobile phone’s operating system.
  8. It is used for compiler production.
  9. It is widely used in IOT applications.

C Basic Commands

Following are the basic commands in C programming language:

C Basic commandsExplanation
#include <stdio.h>This command includes standard input output header file(stdio.h) from the C library before compiling a C program
int main()It is the main function from where C program execution begins.
{Indicates the beginning of the main function.
/*_some_comments_*/Whatever written inside this command “/* */” inside a C program, it will not be considered for compilation and execution.
printf(“Hello_World! “);This command prints the output on the screen.
getch();This command is used for any character input from keyboard.
return 0;This command is used to terminate a C program (main function) and it returns 0.
}It is used to indicate the end of the main function.

CHARACTER CONSTANT IN C PROGRAMMING LANGUAGE

Which is a character constant?A character constant is one or more characters enclosed in single quotes, such as ‘A’ , ‘+’ , or ‘\n’ . In the mikroC PRO for PIC, single-character constants are of the unsigned int type. Multi-character constants are referred to as string constants or string literals.

C Character Constants

  • Article
  • 08/03/2021
  • 2 minutes to read
  • 6 contributors

A “character constant” is formed by enclosing a single character from the representable character set within single quotation marks (‘ ‘). Character constants are used to represent characters in the execution character set

Syntax

character-constant c-char-sequence 

L’ c-char-sequence 

c-char-sequencec-char

c-char-sequence c-char

c-char: Any member of the source character set except the single quotation mark (), backslash (\), or newline character

escape-sequence

escape-sequencesimple-escape-sequence

octal-escape-sequence

hexadecimal-escape-sequence

simple-escape-sequence: one of \a \b \f \n \r \t \v

\’ \” \\ \?

octal-escape-sequence\ octal-digit

\ octal-digit octal-digit

\ octal-digit octal-digit octal-digit

hexadecimal-escape-sequence\x hexadecimal-digit

hexadecimal-escape-sequence hexadecimal-digit

Character Constants

A character constant is one or more characters enclosed in single quotes, such as 'A''+', or '\n'. In the mikroC PRO for PIC, single-character constants are of the unsigned int type. Multi-character constants are referred to as string constants or string literals.

Escape Sequences

A backslash character (\) is used to introduce an escape sequence, which allows a visual representation of certain nongraphic characters. One of the most common escape constants is the newline character (\n).

A backslash is used with octal or hexadecimal numbers to represent an ASCII symbol or control code corresponding to that value; for example, '\x3F' for the question mark. Any value within legal range for data type char (0 to 0xFF for the mikroC PRO for PIC) can be used. Larger numbers will generate the compiler error “Out of range”.

For example, the octal number \777 is larger than the maximum value allowed (\377) and will generate an error. The first nonoctal or nonhexadecimal character encountered in an octal or hexadecimal escape sequence marks the end of the sequence.note  Note : You must use the sequence \\ to represent an ASCII backslash, as used in operating system paths.

The following table shows the available escape sequences:

SequenceValueCharWhat it does
\a0x07BELAudible bell
\b0x08BSBackspace
\f0x0CFFFormfeed
\n0x0ALFNewline (Linefeed)
\r0x0DCRCarriage Return
\t0x09HTTab (horizontal)
\v0x0BVTVertical Tab
\\0x5C\Backslash
\’0x27Single quote (Apostrophe)
\”0x22Double quote
\?0x3F?Question mark
\OanyO = string of up to 3 octal digits
\xHanyH = string of hex digits
\XHanyH = string of hex digits

Disambiguation

Some ambiguous situations might arise when using escape sequences.

Here is an example:

Lcd_Out_Cp("\x091.0 Intro");

This is intended to be interpreted as \x09 and "1.0 Intro". However, the mikroC PRO for PIC compiles it as the hexadecimal number \x091 and literal string ".0 Intro". To avoid such problems, we could rewrite the code in the following way:

Lcd_Out_Cp("\x09" "1.0 Intro");

Ambiguities might also arise if an octal escape sequence is followed by a nonoctal digit. For example, the following constant:

"\118"

would be interpreted as a two-character constant made up of the characters \11 and 8, because 8 is not a legal octal digit.

A character denotes an alphabet, digit or a special character.

Single Character constants:   A single character constant or 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.

For example, ۥAۥ is a valid character constant whereas ‛Aۥ is not. Note that the character constant ۥ 5ۥ is not the same as the number 5.

Valid Character Constants:                             ۥmۥ           ۥ=ۥ            ۥAۥ

ۥInvalid:                                                                 ۥ123ۥ        –     Length should be 1
                                                                               “A”           –     Enclosed in single quotes  

Note: – Each single character constant has an integer value that is determined by the computer’s particular character set.

Rules for Constructing Single Character constants

1.     A single character constant or 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.

2.    The maximum length of a single character constant can be one character.

3.    Each character constant has an integer value that is determined by the computer’s particular character set.

Drop your comment

Related Post

Leave a Reply

Your email address will not be published.