Class 6 Exam  >  Class 6 Notes  >  C Programming for Beginners  >  C Data Types & Constants

C Data Types & Constants | C Programming for Beginners - Class 6 PDF Download

Data Types

As explained in the Variables chapter, a variable in C must be a specified data type, and you must use a format specifier inside the printf() function to display it:

Example

// Create variables

int myNum = 5;             // Integer (whole number)

float myFloatNum = 5.99;   // Floating point number

char myLetter = 'D';       // Character


// Print variables

printf("%d\n", myNum);

printf("%f\n", myFloatNum);

printf("%c\n", myLetter);

Basic Data Types


The data type specifies the size and type of information the variable will store.
In this tutorial, we will focus on the most basic ones:

C Data Types & Constants | C Programming for Beginners - Class 6

Constants

When you don't want others (or yourself) to override existing variable values, use the const keyword (this will declare the variable as "constant", which means unchangeable and read-only):

Example

const int myNum = 15;  // myNum will always be 15

myNum = 10;  // error: assignment of read-only variable 'myNum'

You should always declare the variable as constant when you have values that are unlikely to change:
Example

const int minutesPerHour = 60;

const float PI = 3.14;

Notes On Constants

When you declare a constant variable, it must be assigned with a value:

Example
Like this:

const int minutesPerHour = 60;

This however, will not work:

const int minutesPerHour;

minutesPerHour = 60; // error

Good Practice

Another thing about constant variables, is that it is considered good practice to declare them with uppercase. It is not required, but useful for code readability and common for C programmers:

Example

const int BIRTHYEAR = 1980;

The document C Data Types & Constants | C Programming for Beginners - Class 6 is a part of the Class 6 Course C Programming for Beginners.
All you need of Class 6 at this link: Class 6
10 videos|13 docs|15 tests

Top Courses for Class 6

10 videos|13 docs|15 tests
Download as PDF
Explore Courses for Class 6 exam

Top Courses for Class 6

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Free

,

MCQs

,

C Data Types & Constants | C Programming for Beginners - Class 6

,

practice quizzes

,

video lectures

,

Objective type Questions

,

Viva Questions

,

pdf

,

Previous Year Questions with Solutions

,

C Data Types & Constants | C Programming for Beginners - Class 6

,

Important questions

,

past year papers

,

Sample Paper

,

C Data Types & Constants | C Programming for Beginners - Class 6

,

Semester Notes

,

shortcuts and tricks

,

Extra Questions

,

study material

,

Summary

,

Exam

,

mock tests for examination

,

ppt

;