Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

When should we use pointers in a C program?

1. To get address of a variable


2. For achieving pass by reference in C: Pointers allow different functions to share and modify
their local variables.
3. To pass large structures so that complete copy of the structure can be avoided.
4. To implement “linked” data structures like linked lists and binary trees.

What are main characteristics of C language?


C is a procedural language. The main features of C language include low-level access to
memory, simple set of keywords, and clean style. These features make it suitable for system
programming like operating system or compiler development.

What are the key features of C programming language?

• C is a platform-dependent language.
• C offers the possibility to break down a large program into small modules.
• Also, the possibility of a programmer to control the language.
• C comes with support for system programming and hence it compiles and executes with high
speed when compared to other high-level languages.

What are the basic data types in C?

• Int – Used to represent a number (integer)


• Float – Used to represent a decimal number
• Double – Used to represent a decimal number with highest precision(digits after the decimal
point)
• Char – Single character
• Void – Special purpose type without any value

What is the difference between Arrays and Pointers?

A few differences between Arrays and Pointers are:

• An array is a collection of elements of similar data type whereas the pointer is a variable that
stores the address of another variable.
• An array size decides the number of variables it can store whereas; a pointer variable can store
the address of only one variable in it.
• Arrays can be initialized at the definition, while pointers cannot be initialized at the definition.
Following is the basic structure of a C program.
Documentation Consists of comments, some description of the program, programmer name and any other
useful points that can be referenced later.

Link Provides instruction to the compiler to link function from the library function.

Definition Consists of symbolic constants.

Global Consists of function declaration and global variables.


declaration

main( ) Every C program must have a main() function which is the starting point of the program
{ execution.

Subprograms User defined functions.

Here is the difference between while and do while statement

WHILE DO-WHILE

Condition is checked first then statement(s) is Statement(s) is executed atleast once,

executed. thereafter condition is checked.

It might occur statement(s) is executed zero

times, If condition is false. At least once the statement(s) is executed.


WHILE DO-WHILE

No semicolon at the end of while. Semicolon at the end of while.

while(condition) while(condition);

If there is a single statement, brackets are not

required. Brackets are always required.

Variable in condition is initialized before the variable may be initialized before or within

execution of loop. the loop.

while loop is entry controlled loop. do-while loop is exit controlled loop.

while(condition) do { statement(s); }

{ statement(s); } while(condition);

What are Pointers?

A pointer is a variable whose value is the address of another variable, i.e., direct address of the
memory location. Like any variable or constant, you must declare a pointer before using it to
store any variable address.
C Keywords

Keywords are predefined, reserved words used in programming that have special meanings to the
compiler. Keywords are part of the syntax and they cannot be used as an identifier.

C Identifiers

Identifier refers to name given to entities such as variables, functions, structures etc.

Identifiers must be unique. They are created to give a unique name to an entity to identify it
during the execution of the program.
Arrays in C

An array in C is a collection of items stored at contiguous memory locations and elements can be
accessed randomly using indices of an array. They are used to store similar type of elements as in
the data type must be the same for all elements. They can be used to store collection of primitive
data types such as int, float, double, char, etc of any particular type. To add to it, an array in C
can store derived data types such as the structures, pointers etc.

Advantages of Array in C Programming

• It is better and convenient way of storing the data of same datatype with same size.

• It allows us to store known number of elements in it.

• It allocates memory in contiguous memory locations for its elements. It does not allocate
any extra space/ memory for its elements. Hence there is no memory overflow or
shortage of memory in arrays.

• Iterating the arrays using their index is faster compared to any other methods like linked
list etc.

• It allows to store the elements in any dimensional array - supports multidimensional


array.

Definition of 'Debugging'

Definition: Debugging is the process of detecting and removing of existing and potential errors
(also called as ‘bugs’) in a software code that can cause it to behave unexpectedly or crash. To
prevent incorrect operation of a software or system, debugging is used to find and resolve bugs
or defects. When various subsystems or modules are tightly coupled, debugging becomes harder
as any change in one module may cause more bugs to appear in another. Sometimes it takes
more time to debug a program than to code it.

Here’s the debugging process:

1. Reproduce the problem.

2. Describe the bug. Try to get as much input from the user to get the exact reason.
3. Capture the program snapshot when the bug appears. Try to get all the variable values and
states of the program at that time.

4. Analyse the snapshot based on the state and action. Based on that try to find the cause of the
bug.

5. Fix the existing bug, but also check that any new bug does not occur.

Difference between Compiler and Interpreter

BASIS FOR
COMPILER INTERPRETER
COMPARISON

Input It takes an entire program at a It takes a single line of code or

time. instruction at a time.

Output It generates intermediate object It does not produce any

code. intermediate object code.

Working mechanism The compilation is done before Compilation and execution take

execution. place simultaneously.

Speed Comparatively faster Slower

Memory Memory requirement is more It requires less memory as it does

due to the creation of object not create intermediate object code.


BASIS FOR
COMPILER INTERPRETER
COMPARISON

code.

Errors Display all errors after Displays error of each line one by

compilation, all at the same one.

time.

Error detection Difficult Easier comparatively

Pertaining C, C++, C#, Scala, typescript PHP, Perl, Python, Ruby uses an

Programming uses compiler. interpreter.

languages

You might also like