Chapter 8

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

CHAPTER 8

What are uses of preprocessor directives? (2)


Preprocessor directives in C and C++ are commands that are executed before the compilation process.
They are used to include header files, define constants. For example, #include <stdio.h> is a
preprocessor directive that includes the standard input-output library in a program.

Diferentiate between Linker and Loader?


Linker: The linker puts together the pieces of your program to make it ready to run. It connects
different parts of your code and external libraries to create an executable file.

Loader: The loader takes the executable file created by the linker and puts it into memory so it can be
run. It makes sure everything the program needs is in place and ready to go.

Give two examples of run time errors.


 Division by zero: int result = 10 / 0;
 Accessing an invalid memory location: int* ptr; *ptr = 10;

What will happen if stdio.h file is missing in a C program?


If the stdio.h file is missing in a C program, the compiler will not be able to find the declarations for
standard input-output functions like printf and scanf. This will result in compilation errors when you
try to use these functions in your program.

Differentiate between Constant and Variable.


 Constant: A constant is a value that cannot be changed during program execution.
For example, const int MAX_SIZE = 100; defines a constant MAX_SIZE with a value of
100.
 Variable: A variable is a storage location in memory that can hold different values
during program execution. For example, int count = 0; defines a variable count that can
hold integer values.

What is garbage value?. (2)


Garbage value refers to an unpredictable value that is stored in a variable or memory location.
It occurs when a variable is not initialized or is assigned a value that is not valid for its data
type. Examples:
Printing the value of an uninitialized variable: int x; printf("%d", x);

Give any four examples of high level languages


 Python
 Java
 C#
 JavaScript

Write down the use of Turbo C++. (2)


Turbo C++ was an Integrated Development Environment (IDE) and compiler for the C++
programming language. It was used for writing, compiling, and debugging C++ programs. It provided
a user-friendly interface and was popular in the 1990s and early 2000s for DOS and Windows
development. However, it's no longer commonly used today as more modern and efficient
development tools have replaced it.

C-Language Write shortcut key to compile and run?


There isn't a universal shortcut key for compiling and running C programs, as it depends on the
development environment you're using. In many environments, you can use F5 or Ctrl+F5 to compile
and run a program. For command-line compilers, you typically need to type the compilation and
execution commands separately.

What is the use of define preprocessor?


The define preprocessor directive in C is used to define a constant or a macro. It allows you to give a
name to a constant value or a block of code, which can make your code more readable and
maintainable. For example #define PI 3.14159

Define delimiters.
Delimiters are like separators that help computer programs understand where one part of the
information ends and another begins. For example, in a list of numbers separated by commas, the
commas act as delimiters, showing where each number starts and stops.

Why C is known as strongly typed language?


C is called strongly typed because it requires you to be clear about the types of data you're using. You
can't mix different types without saying so. For example, if you try to use a number where a word is
expected, or the other way around, C will ask you to be more specific.

Long Question
What is programming language? Describe two categories of programming
languages.

Define bug. Discuss different types of bugs in c language.


CHAPTER 9
Declare an integer variable with name marks and store 799 in it.
int marks = 799;

Predict output of the code given below


int a=27, b=19;

printf("% d+% d=%d", a, b, a+b);

Output: 27 + 19 = 46

Trace out errors from following code segment


Void main(); Doubt = 45; printF("%f",t)

int Doubt = 45;

printf("%f", Doubt);

Correction: Use %d instead of %f for int variable.

How is the end of a text file indicated?


The end of a text file is indicated by pressing Ctrl+D (Unix/Linux) or Ctrl+Z (Windows) at the
beginning of a new line in the input stream.

does cancellation error occur?


Cancellation Error:
 A cancellation error can occur in floating-point arithmetic when subtracting two very
close numbers. Due to the limited precision of floating-point numbers, the result may
not be accurate and can lead to unexpected behavior in numerical computations.

vi Write output of the following code: int x = 5;


printf("%d %d", 2 * x, 3 * x);

Output: 10 15

vii Name any four format specifiers provided by C.


Format specifiers provided by C:
 %d for integers
 %f for floating-point numbers
 %c for characters
 %s for strings
viii Write output of the following code:
int a, b, c;
a = 15;
b = 10;
c = a+b;
printf("c=%d", --c);

1. Output: c=24

#include <stdio.h>

int main()

int x = 5, y;

y = x++;

printf ("%d %d", x, y);

return 0;

Output: 6 5

Long

Write any eight rules for naming variables in C-

You might also like