Structure of a C program, Identifier, Literals को जाने - easy4tuts.blogspot.com

Hot Contents To Know

Post Top Ad

Your Ad Spot

Structure of a C program, Identifier, Literals को जाने

Q Describe the structure of a C program?

A C program basically consists of the following parts:

         Preprocessor Directives

         Functions

         Variables

         Statements &Expressions

         Comments

A C program is a collection of one or more functions. The general structure of a C program is-

Comments
Preprocessor Directives
Global variables

main()
{
     local variables
     statements  
     ................
     ................

}

Func1()
{

    Local variables
    statements
    ...............
    ..........

C programming language मे program का बनावट इस प्रकार होता है:- 

Example:- Write a program in C for displaying a message?

Q  What are Tokens or elements of C program?        

A smallest unit of a program is called tokens. A C program consists of various tokens. A token is a keyword, an identifier, a constant, a string literal, or a symbol. The individual tokens are:

 

1.      Semicolons:- In a C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.

2.      Escape Sequences/Execution Characters:-Escape Sequence are used to print those characters which cannot be printed like other normal character on the screen of a computer in C. Escape sequences are character combinations of back slash(\) and any character set of C language. There are certain characters in C that represent special meaning when preceded by a backslash, for example, newline (\n) or tab (\t).

3.      Keywords:-Keywords have standard and predefined meaning in C language. These reserved words may not be used as constants or variables or any other identifier names. There are 32 keywords in C. Some of them are-auto, break, case, char etc..

4.      Identifiers:-A C identifier is a name used to identify a variable, function, or any other user- defined item. An identifier starts with a letter A to Z, a to z, or an underscore ‘_’ followed by zero or more letters, underscores, and digits (0 to 9).

Q What are identifiers?

 Identifiers are user defined words. They are used to give name to variables, array, functions, structures, union etc.. Rules for naming identifiers are-

1.      The name should consist of only alphabets, digits and underscore sign (_).

2.      First character should be alphabets or underscore

3.      The name should not be a keyword.

4.      Since C is a case sensitive, the uppercase and lowercase letters are considered different.

5.      An identifier name may be 31 characters long.

 

Q What are data types?

The Data type of a variable determines how much space  it occupies in storage and how the bit pattern stored is interpreted. There are four fundamental data types in C, that is-

int:-is used to store integer value.
char:-is used to store any single character.
float:-is used for storing single precision floating points number.
double:-is used for storing double precision floating point number.

Two Type Qualifiers are used to represent more data types. These are
(1)Size qualifiers-short, long
(2)Sign qualifiers-signed, unsigned

The size and range of different data types on a 16-bit machine is as follow-

 

 

 

Basic Data Types

 

Data Types with type qualifiers

 

Storage size

 

Value range

char

 

Char or signed char

 

1

 

1byte

 

-128 to 127

 

unsigned char

 

1

 

1byte

 

0 to 255

Int

 

int or signed  int

 

2

 

2bytes

 

-32768 to 32767

 

unsigned int

 

2

 

2bytes

 

0 to 65,535

 

Short int or signed short int

 

1

 

 

1byte

 

-128 to 127

 

Unsigned short int

 

1

 

1bytes

 

0 to 255

 

Long int or signed long int

 

4

 

4bytes

 

-2,147,483,648 to 2,147,483,647

 

unsigned long int

 

4

 

4bytes

 

0 to 4,294,967,295

 

 

 

 

 

 

 

 

Type

 

Storage size

 

Value range

 

Precision

 

Float

 

4 byte

 

1.2E-38 to 3.4E+38

 

6 decimal places

 

Double

 

8 byte

 

2.3E-308 to 1.7E+308

 

15 decimal places

 

long double

 

10 byte

 

3.4E-4932 to 1.1E+4932

 

19 decimal places

 

Q What are constants in C?

Constants refer to fixed values that the program may not change during its execution. These fixed values are also called literals.

Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string constant. There are user defined constants also.

Constants are treated just like regular variables except that their values cannot be modified after their definition.

 

Integer Literals:- An integer literal can be a decimal, octal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, 0 for octal, and nothing for decimal. An integer literal can also have a suffix that is a combination of U and L, for unsigned and long, respectively. The suffix can be uppercase or lowercase and can be in any order.

Floating-point Literals:- A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. We can represent floating point literals either in decimal form or exponential form.

Character literals:- Character literals are enclosed in single quotes, e.g., 'x' can be stored in a simple variable of char type.

A character literal can be a plain character (e.g., 'x'), an escape sequence (e.g., '\t'), or a universal character (e.g., '\u02C0').

String Literals:- String literals or constants are enclosed in double quotes "". A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters.

 

Q What are header files in C?

Header files are collections of built-in functions with .h extension. It contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that come with our compiler. The files that the programmer writes, is called source file. The file that comes with every compiler is called header file. Each header files contains group of built-in functions. We request to use a header file in our program by including it with the C preprocessing directive #include. Including a header file is equal to copying the content of the header file into source file. The syntax for using header files in our program is:-

#include <file_namewith_extension>

Some Common header files are:-

No.

Name

Description

1

stdio.h

Standard input/output Functions

2

conio.h

Console input/output

3

complex.h

Manipulating complex number

4

ctype.h

Character Handling Functions

5

math.h

Mathematics Functions

6

stdlib.h

General Utility Functions

7

string.h

String Functions

8

time.h

Date and Time Functions

10

stdbool.h

Defines a boolean data type

No comments:

Post a Comment

Post Top Ad

Your Ad Spot