Declaring a Variable of Type "long" in C programming
How to Declare a long Variable in C
In C programming, the long data type is used when you need a variable capable of holding larger integer values than the standard int. The long data type is typically 4 or 8 bytes in size, depending on the system architecture.
Declaring a long Variable
To declare a variable of type long in C, you can use the following syntax:
long variableName;
Here, variableName is the name you choose for the variable. For example:
long myNumber;
This statement declares a variable named myNumber of type long.
Example: Declaring and Initializing a long Variable
In most cases, you will declare and initialize a long variable at the same time. Here’s an example:
#include <stdio.h>
int main() {
long myNumber = 1234567890L;
printf("The value of myNumber is: %ld\n", myNumber);
return 0;
}
In this example:
myNumberis declared as alongand initialized with the value1234567890L.- The
Lsuffix indicates that the literal value is of typelong.
Note: When printing a
long variable using printf, use the format specifier %ld for signed long integers.
Comments
Post a Comment