- C Programming Basics
- C Tutorial
- C Program Structure
- C Basic Syntax
- C Data Types
- C Constants
- C Variables
- C Operators
- C Ternary Operator
- C Storage Classes
- C Flow of Control
- C Decision Making
- C if if-else Statement
- C switch Statement
- C Loops
- C for Loop
- C while Loop
- C do-while Loop
- C goto Statement
- C break Statement
- C continue Statement
- C Popular Topics
- C Arrays
- C Strings
- C Pointers
- C Functions
- C Recursion
- C Scope Rules
- C Programming Advance
- C Structures
- C Unions
- C Bit Fields
- C Enumerations
- C Input & Output
- C Typedef
- C Preprocessors
- C Type Casting
- C Recursion
- C Error Handling
- C Linked Lists
- C Stacks
- C Queues
- C Binary Trees
- C Header Files
- C File I/O
- C Variable Arguments
- C Memory Management
- C Command Line Arguments
- C Programming Examples
- C Programming Examples
- C Programming Test
- C Programming Test
C Constants
Constants refer to a fixed values that the program may not alter. Constants can be of any of the basic data types. The style each constant is represented simply depends upon its type.
Character constants are enclosed in between single quotes. For example, 'a', 'c', and '%' are character constants. String constants are enclosed in between double quotes. For example, "str", "anish", and also "a" (is a string constant containing only one character) are string constants.
Following table lists some of the examples of constants:
Data Type | Constant Example |
---|---|
int | 1, 23, 450, -32 |
long int | 25000L, -45L |
unsigned int | 1000U, 345u, 20000U |
float | 123.32F, 5.3e-4f |
double | 124.32, 1.0, -0.943234 |
long double | 1001.2L |
Hexadecimal and Octal Constants
Here are examples of hexadecimal and octal constants:
int hex = 0x80; // 128 in decimal int oct = 012; // 10 in decimal
Here we have listed number conversion programs that you can go for:
- Decimal to Octal Conversion
- Decimal to Hexadecimal Conversion
- Binary to Octal Conversion
- Binary to Hexadecimal Conversion
- Octal to Decimal Conversion
- Octal to Binary Conversion
- Octal to Hexadecimal Conversion
- Hexadecimal to Decimal Conversion
- Hexadecimal to Binary Conversion
- Hexadecimal to Octal Conversion
Backslash Character Constants
Enclosing character constants in single quotes works for most printing characters. Here the following table lists the backslash character constants:
Backslash Character Constant | Name |
---|---|
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Carriage return |
\t | Horizontal tab |
\' | Single quote |
\" | Double quote |
\\ | Backslash |
\v | Vertical tab |
\a | Alert |
\? | Question mark |
\N | Octal constants (here N is an octal constant) |
\xN | Hexadecimal constants (here N is a hexadecimal constant) |
Backslash Character Constants Example
Here is an example program using backslash character constants:
/* C Constants - Backslash Character Constants Program */ #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int num1, num2, num3; char str1[20], str2[20]; clrscr(); printf("Enter a number: "); scanf("%d", &num1); printf("You entered\n%d", num1); fflush(stdin); printf("\n\nEnter your name: "); gets(str1); printf("Your name is \"%s\"", str1); fflush(stdin); printf("\n\nEnter the two number: "); scanf("%d%d", &num2, &num3); printf("You entered :\n%d\t%d\n", num2, num3); fflush(stdin); printf("\n\nWho are you ? "); gets(str2); printf("Are you a %s\?", str2); getch(); }
Here is the sample run of the above C program:

C #define Preprocessor
Here is the general form to use #define preprocessor to define a constant in C:
#define identifier value
Here is an example program illustrating the #define preprocessor:
/* C Constants = This program demonstrates * the use of #define preprocessor */ #include<stdio.h> #include<conio.h> #define LENGTH 5 #define BREADTH 6 #define NEWLINE '\n' void main() { int cal_area; char str[20]; clrscr(); printf("Enter your name: "); gets(str); printf("%s%c", str, NEWLINE); cal_area = LENGTH * BREADTH; printf("The area value is %c%d", NEWLINE, cal_area); getch(); }
Here is the sample run of the above C program:

C const Keyword
You can use the const prefix to declare constants with a specific type. Here is the general form to declare constants using the keyword const:
const type variable = value;
Here is an example program demonstrating the const keyword in defining the constants in C language:
#include<stdio.h> #include<conio.h> void main() { const int LENGTH = 6; const int BREADTH = 5; const char NEWLINE = '\n'; int cal_area; char str[20]; clrscr(); printf("Enter your name: "); gets(str); printf("%s%c", str, NEWLINE); printf("The area value is %c%d", NEWLINE, LENGTH*BREADTH); getch(); }
Following is the sample output of the above C program:

Number Conversion Programs
Here are the list of complete number conversion programs that you can go for:
- Decimal to Binary Conversion
- Binary to Decimal Conversion
- Binary to Hexadecimal Conversion
- Octal to Decimal Conversion
- Hexadecimal to Decimal Conversion
« Previous Tutorial Next Tutorial »
Follow/Like Us on Facebook
Subscribe Us on YouTube