C প্রোগ্রামিংয়ের int Data Type সম্পর্কে আলোচনা

Submitted by tushar pramanick on Tue, 03/05/2013 - 14:45

The int Data Type

You saw the integer data type in Hour 3. The int keyword is used to specify the type of a variable as an integer. Integer numbers are also called whole numbers, which have no fractional part or decimal point. Therefore, the result of an integer division is truncated, simply because any fraction part is ignored.

 

Depending on the operating system and the C compiler you're using, the length of an integer varies. On most UNIX workstations, for example, an integer is 32 bits long, which means that the range of an integer is from 2147483647 (that is, 231_1) to -2147483648. The range of a 16-bit integer is from 32767 (that is, 215_1) to -32768.

 

The C compiler I'm using for this book is Visual C++ 1.5, which only provides the 16-bit integer, while a 32-bit version of Visual C++, such as Visual C++ 4.0 or Visual C++ 5.0, supports the 32-bit integer.

 

Declaring Integer Variables

You also saw the declaration of an integer in Hour 3. The following shows the basic declaration format:

 

int  variablename;

 

Similar to the character declaration, if you have more than one variable to declare, you can use either the format like this

 

int  variablename1;
int  variablename2;
int  variablename3;

 

or like this:

 

int  variablename1, variablename2, variablename3;

 

Here variablename1, variablename2, and variablename3 indicate the places where you put the names of int variables.
Showing the Numeric Values of Characters

 

Like the character format specifier (%c) that is used to format a single character, %d, called the integer format specifier, is used to format an integer. You might recall that in line 16 of Listing 3.2, %d is used in the printf() function to format the second argument of the function to an integer.

 

In this section you're going to study a program, shown in Listing 4.3, that can print out the numeric values of characters by using the integer format specifier %d with printf().

 

TYPE
Listing 4.3. Showing the numeric values of characters.

 

1:  /* 04L03.c: Showing the numeric values of characters */
2:  #include <stdio.h>
3:
4:  main()
5:  {
6:     char c1;
7:     char c2;
8:
9:     c1 = `A';
10:    c2 = `a';
11:    printf("The numeric value of A is: %d.\n", c1);
12:    printf("The numeric value of a is: %d.\n", c2);
13:    return 0;
14: }

 

OUTPUT
I get the following output on the screen after running the executable file, 04L03.exe:

C:\app> 04L03
The numeric value of A is: 65.
The numeric value of a is: 97.
C:\app>

 

ANALYSIS
 You may find that the program in Listing 4.3 is quite similar to the one in Listing 4.1. As a matter of fact, I simply copied the source code from Listing 4.1 to Listing 4.3 and made changes in lines 11 and 12. The major change I made was to replace the character format specifier (%c) with the integer format specifier (%d).

 

The two statements in lines 11 and 12 format the two character variables (c1 and c2) by using the integer format specifier %d, and then print out two messages showing the numeric values 65 and 97 that represent, respectively, the characters A and a in the ASCII character set.

Comments

Related Items

মডুলার C প্রোগ্রামিং (Modular C Programming)

কেবল মাত্র একটি ফাংশন দিয়ে কোনো বড়ো জটিল সমস্যা সমাধানের চেষ্টা করা ভাল প্রোগ্রামিংয়ের পদ্ধতি নয়। সঠিক পদ্ধতি হ'ল সমস্যাটিকে কয়েকটি ছোট ছোট এবং সরল টুকরো করে ফেলা যাতে তা আরও বিশদে বোঝা যায় । তারপরে এই ছোট এবং সরল সমস্যাগুলি সমাধান করার জন্য ছোট ছোট ফাংশন ব্লক তৈরি করা এবং পরে সেগুলি নিয়মানুযায়ী সংযোজিত করা ।

Programming Style

Programming Style

In this section, I'd like to briefly highlight some points that will help you write clean programs that can easily be read, understood, and maintained.

Exercises : Answer the following Question

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

Question and Answer

    Q Is the C preprocessor part of the C compiler?

    A No. The C preprocessor is not part of the C compiler. With its own line-oriented grammar and syntax, the C preprocessor runs before the compiler in order to handle named constants, macros, and inclusion of files.

Compiling Your Code Under Conditions

Compiling Your Code Under Conditions

You can select portions of your C program that you want to compile by using a set of preprocessor directives. This is useful, especially when you're testing a piece of new code or debugging a portion of code.