You are on page 1of 5

MCA 105 (PROGRAMMING IN C)

Q-1. What is “C” Tokens?

Ans Q-1:

The basic and smallest unit of a C program is called C tokens.

There are six types of token in C.

1. Keywords: Keywords are special words that are used to give a special meaning to the program
and can’t be used as variable and constant. They are basically a sequence of characters that have
fixed to mean for example break, for, while, do-while, do, if, int, long, char.

2. Identifiers: Identifiers are the sequence of alphabets and digit, but keyword should not be used
as an identifier.

3. Constants: The quantity which does not change during the execution of a program is known as
constant. There are types of constant.
1- Integer constant
2- Real constant
3- Character constatnt

4. Variables: Variables are used to give the name and allocate memory space. An entity that may
vary data during execution. For example, sum, area, a, b, age, city.

5. String: String is a collection of more than one character. For example, “RAM”, “Meerut”, “Star”
String is represented by a pair of double quotes.

6. Operators: Operators acts as connectors and they indicate what type of operation is being
carried out. The values that can be operated by these operators are called operands. They are used
to perform basic operations, comparison, manipulation of bits and so on.

Q-2. Write the steps to Compile and Execute C Program?

Ans:-2

Knowing how compilation works can be very helpful both when writing code and when
debugging.

Compiling a C program is a multi-stage process. At an overview level, the process can be split
into four separate stages: Preprocessing, compilation, assembly, and linking.

Preprocessing
The first stage of compilation is called preprocessing. In this stage, lines starting with
a #character are interpreted by the preprocessor as preprocessor commands. These commands
form a simple macro language with its own syntax and semantics. This language is used to
reduce repetition in source code by providing functionality to inline files, define macros, and to
conditionally omit code.
Before interpreting commands, the preprocessor does some initial processing. This includes
joining continued lines (lines ending with a \) and stripping comments.

Compilation
The second stage of compilation is confusingly enough called compilation. In this stage, the
preprocessed code is translated to assembly instructions specific to the target processor
architecture. These form an intermediate human readable language.

The existence of this step allows for C code to contain inline assembly instructions and for
different assemblers to be used.

Some compilers also supports the use of an integrated assembler, in which the compilation stage
generates machine code directly, avoiding the overhead of generating the intermediate assembly
instructions and invoking the assembler.

Assembly
During this stage, an assembler is used to translate the assembly instructions to object code. The
output consists of actual instructions to be run by the target processor.

Linking
The object code generated in the assembly stage is composed of machine instructions that the
processor understands but some pieces of the program are out of order or missing. To produce
an executable program, the existing pieces have to be rearranged and the missing ones filled in.
This process is called linking.

The linker will arrange the pieces of object code so that functions in some pieces can
successfully call functions in other ones. It will also add pieces containing the instructions for
library functions used by the program. In the case of the “Hello, World!” program, the linker
will add the object code for the puts function.

Execution of program

Whenever we give the command to execute a particular program, the loader comes into work. The loader

will load the .exe file in RAM and inform the CPU with the starting point of the address where this program

is loaded.

Instruction Register: It holds the current instructions to be executed by the CPU.


Program Counter: It contains the address of the next instructions to be executed by the CPU.
Accumulator: It stores the information related to calculations.

The loader informs Program Counter about the first instruction and initiates the execution. Then onwards,
Program Counter handles the task.
Q-3. What do you mean by Integer Literals?

ANS- Constants refer to fixed values that the program may not alter 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 literal. There are enumeration constants
as well.
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.
Here are some examples of integer literals −
212 /* Legal */
215u /* Legal */
0xFeeL /* Legal */
078 /* Illegal: 8 is not an octal digit */
032UU /* Illegal: cannot repeat a suffix */

Following are other examples of various types of integer literals −


85 /* decimal */
0213 /* octal */
0x4b /* hexadecimal */
30 /* int */
30u /* unsigned int */
30l /* long */
30ul /* unsigned long */

Q-4. Write about The register Storage Class? With example

Ans-

Register Storage Class :

1. Register keyword is used to define local variable.

2. Local variable are stored in register instead of RAM.

3. As variable is stored in register, the Maximum size of variable = Maximum Size of Register

4. unary operator [&] is not associated with it because Value is not stored in RAM instead it is stored in Register.

5. This is generally used for faster access.


6. Common use is “Counter“

Syntax
{
register int count;
}

Register storage classes example


#include<stdio.h>

int main()
{
int num1,num2;
register int sum;

printf("\nEnter the Number 1 : ");


scanf("%d",&num1);

printf("\nEnter the Number 2 : ");


scanf("%d",&num2);

sum = num1 + num2;

printf("\nSum of Numbers : %d",sum);

return(0);
}

Q-5. What are the differences between Continue and Break statement?

Ans- The major difference between break and continue statements in C language is that a break causes the
innermost enclosing loop or switch to be exited immediately. Whereas, the continue statement causes the
next iteration of the enclosing for, while, or do loop to begin. The continue statement
in while and do loops takes the control to the loop's test-condition immediately, whereas in the for loop it
takes the control to the incrementstep of the loop.
The continue statement applies only to loops, not to switch. A continue inside a switch inside a loop
causes the next loop iteration.
Practically, break is used in switch, when we want to exit after a particular case is executed; and in loops,
when it becomes desirable to leave the loop as soon as a certain condition occurs (for instance, you detect
an error condition, or you reach the end of your data prematurely).
The continue statement is used when we want to skip one or more statements in loop's body and to
transfer the control to the next iteration.
Difference Between break and continue
Difference Between break and continue

Break continue

A break can appear in both switch and loop A continue can appear only in loop
(for, while, do) statements. (for, while, do) statements.

A break causes the switch or loop statements to A continue doesn't terminate the loop, it
terminate the moment it is executed. Loop causes the loop to go to the next iteration. All
or switch ends abruptly when break is encountered. iterations of the loop are executed even
if continue is encountered.
The continue statement is used to skip
statements in the loop that appear after
the continue.
The break statement can be used in The continue statement can appear only in
both switch and loop statements. loops. You will get an error if this appears in
switch statement.
When a break statement is encountered, it When a continue statement is encountered, it
terminates the block and gets the control out of gets the control to the next iteration of the loop.
the switch or loop.

A break causes the innermost enclosing loop A continue inside a loop nested within
or switch to be exited immediately. a switch causes the next loop iteration.

You might also like