Declare variable as constant in C (2024)

'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });

Variables can be declared as constant using the const keyword or the #define preprocessor directive. Details about these are given as follows.

Variables can be declared as constants by using the “const” keyword before the datatype of the variable. The constant variables can be initialized once only. The default value of constant variables are zero.

See Also
Atomic locks

A program that demonstrates the declaration of constant variables in C using const keyword is given as follows.

The output of the above program is as follows.

Variables can be declared as constants by using the #define preprocessor directive as it declares an alias for any value.

A program that demonstrates the declaration of constant variables in C using #define preprocessor directive is given as follows.

The output of the above program is as follows.

Declare variable as constant in C (2024)
Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 5996

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.