(to directly see the answer click on that question ) q-1 ... · (to directly see the answer click...

14
https://cseexamhacks.wordpress.com/ (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between compilers VS Interpreters in C language? Q-3:What are Data Types ? Q-4:What are printf( ) and scanf( ) function? Q-5:What are Token in C? Q-6:What are Identifiers in C? Q-7:What are Keyword in C? Q-8:What are Backslash Character Constants in C? Q-9:What is Variable ? Q-10: Difference between variable declaration & variable definition in C? Q-11: What are Operators and Expressions in C? Q-12: Different type of Operators in C? Q-13: What are Increment/decrement Operators? Q-14:What are “If”, “else” and nested ifdecision control statements in C? Q-15:What are Loop control statements in C? Q-16:What are Types of Loop control statements in C? Q-17: Difference Between while&do while” loops in C language? Q-18: What are Case control statements? Q-19:What do you mean by Storage Class Specifiers? Q-20:What are Arrays? Q-21:What are Strings? Q-22:What are C String functions? Q-23:What are Pointers? Q-24:What are Functions? Q-25:What are uses of Functions? Q-26: What are 3 aspects in each C function ? Q-27:Difference Between Call by Value & Call by Reference? Q-28:What are User defined functions in C? Q-29: What is Dynamic memory allocation in C? Q-30:What is a Structure ? Q-31:What is the Difference between C variable, C array and C structure? Q-32:What are Array of Structure? Q-33:What’s the Difference between static memory allocation and dynamic memory allocation in C? Q-34:What is Type Casting ? Q-35:What is Typedef? Q-36:What is Union? Q-37: Difference between structure and union in C? Q-38:What is File? Q-39:What are Basic file operations in C programming? Q-40:What are some Inbuilt functions for file handling in C language?

Upload: others

Post on 25-Apr-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

(To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between compilers VS Interpreters in C language?

Q-3:What are Data Types ?

Q-4:What are printf( ) and scanf( ) function?

Q-5:What are Token in C?

Q-6:What are Identifiers in C?

Q-7:What are Keyword in C?

Q-8:What are Backslash Character Constants in C?

Q-9:What is Variable ?

Q-10: Difference between variable declaration & variable definition in C?

Q-11: What are Operators and Expressions in C?

Q-12: Different type of Operators in C?

Q-13: What are Increment/decrement Operators?

Q-14:What are “If”, “else” and “nested if” decision control statements in C?

Q-15:What are Loop control statements in C?

Q-16:What are Types of Loop control statements in C?

Q-17: Difference Between ”while”&”do while” loops in C language?

Q-18: What are Case control statements?

Q-19:What do you mean by Storage Class Specifiers?

Q-20:What are Arrays?

Q-21:What are Strings?

Q-22:What are C String functions?

Q-23:What are Pointers?

Q-24:What are Functions?

Q-25:What are uses of Functions?

Q-26: What are 3 aspects in each C function ?

Q-27:Difference Between Call by Value & Call by Reference?

Q-28:What are User defined functions in C?

Q-29: What is Dynamic memory allocation in C?

Q-30:What is a Structure ?

Q-31:What is the Difference between C variable, C array and C structure?

Q-32:What are Array of Structure?

Q-33:What’s the Difference between static memory allocation and dynamic memory

allocation in C?

Q-34:What is Type Casting ?

Q-35:What is Typedef? Q-36:What is Union? Q-37: Difference between structure and union in C?

Q-38:What is File?

Q-39:What are Basic file operations in C programming?

Q-40:What are some Inbuilt functions for file handling in C language?

Page 2: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

VIVA

QUESTION’s

Computer Science

Q-1: What is Pre-Processor directives? Ans:

Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. This process is called preprocessing. Commands used in preprocessor are called

preprocessor directives and they begin with “#” symbol.

Q-2: Difference between compilers VS Interpreters in C language?

Ans:

Compilers Interpreters

Compiler reads the entire source code of the

program and converts it into binary code. This

process is called compilation.

Binary code is also referred as machine code,

executable, and object code.

Interpreter reads the program source code one

line at a time and executing that line. This

process is called interpretation.

Program speed is fast. Program speed is slow.

One time execution.

Example: C, C++

Interpretation occurs at every line of the

program.

Example: BASIC

Q-3:What are Data Types ? Ans:

• C data types are defined as the data storage format that a variable can store a data to perform a specific operation.

• Data types are used to define a variable before to use in a program.

• Size of variable, constant and array are determined by data types.

Some Types of data Type are:

*”()” represents the size.

Types Data Types

Basic data types int(2), char(1), float(4), double(8)

Enumeration data type enum

Derived data type pointer, array, structure, union

Void data type void

Page 3: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-4:What are printf( ) and scanf( ) function?

Ans: printf() and scanf() functions are inbuilt

library functions in C programming language which are available in C library by default. These

functions are declared and related macros are defined in “stdio.h” which is a header file in C

language. printf() is used to display the output and scanf() is used to read the inputs.

Q-5:What are Token in C? Ans: C tokens are the basic buildings blocks in C language which are constructed together to

write a C program.

C tokens are of six types. They are,

1. Keywords (eg: int, while),

2. Identifiers (eg: main, total),

3. Constants (eg: 10, 20),

4. Strings (eg: “total”, “hello”),

5. Special symbols (eg: (), {}),

6. Operators (eg: +, /,-,*)

Q-6:What are Identifiers in C? Ans: Each program elements in a C program are given a name called identifiers.

Q-7:What are Keyword in C?

Ans: • Keywords are pre-defined words in a C compiler. • Each keyword is meant to perform a specific function in a C program. • Since keywords are referred names for compiler, they can‟t be used as variable name.

Q-8:What are Backslash Character Constants in C?

Ans:

• There are some characters which have special meaning in C language.

• They should be preceded by backslash symbol to make use of special function of them.

• i.e ( \n –New Line)

Q-9:What is Variable ? Ans: C variable is a named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable. The value of the C variable may get change in

the program.

Q-10: Difference between variable declaration & variable definition in C:

Variable declaration Variable definition

Declaration tells the compiler about data type and

size of the variable.

Definition allocates memory for the

variable.

Variable can be declared many times in a program. It can happen only one time for a variable

in a program.

The assignment of properties and identification to a

variable.

Assignments of storage space to a

variable.

Page 4: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-11: What are Operators and Expressions

in C? Ans:

• The symbols which are used to perform logical and mathematical operations in a C

program are called C operators.

• These C operators join individual constants and variables to form expressions.

• Operators, functions, constants and variables are combined together to form expressions.

• Consider the expression A + B * 5. where, +, * are operators, A, B are variables, 5 is

constant and A + B * 5 is an expression.

Q-12: Different type of Operators in C?

Ans:

Types of Operators Description

Arithmetic operators These are used to perform mathematical calculations like addition,

subtraction, multiplication, division and modulus

Assignment_operators These are used to assign the values for the variables in C programs.

Relational operators These operators are used to compare the value of two variables.

Logical operators These operators are used to perform logical operations on the given

two variables.

Bit wise operators These operators are used to perform bit operations on given two

variables.

Conditional (ternary)

operators

Conditional operators return one value if condition is true and

returns another value is condition is false.

Increment/decrement

operators

These operators are used to either increase or decrease the value of

the variable by one.

Special operators &, *, sizeof( ) and ternary operators.

Q-13: What are Increment/decrement Operators? Ans:

Increment operators are used to increase the value of the variable by one and decrement operators are

used to decrease the value of the variable by one in C programs.

i.e ,

Increment operator : ++ i ; i ++ ;

Decrement operator : – – i ; i – – ;

Page 5: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-14:What are “If”, “else” and “nested if”

decision control statements in C? Ans:

Decision control

statements

Syntax/Description

if

Syntax:

if (condition)

{ Statements; }

Description:

In these type of statements, if condition is true, then respective block of

code is executed.

if…else

Syntax:

if (condition)

{ Statement1; Statement2; }

else

{ Statement3; Statement4; }

Description:

In these type of statements, group of statements are executed when

condition is true. If condition is false, then else part statements are

executed.

nested if

Syntax:

if (condition1){ Statement1; }

else if(condition2)

{ Statement2; }

else Statement 3;

Description:

If condition 1 is false, then condition 2 is checked and statements are

executed if it is true. If condition 2 also gets failure, then else part is

executed.

Page 6: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-15:What are Loop control statements in C?

Ans: Loop control statements in C are used to

perform looping operations until the given

condition is true. Control comes out of the loop statements once condition becomes false.

Q-16:What are Types of Loop control statements in C?

Ans:

Loop Name Syntax

for

for (exp1; exp2; expr3)

{ statements; } Where,

exp1 – variable initialization

( Example: i=0, j=2, k=3 )

exp2 – condition checking

( Example: i>5, j<3, k=3 )

exp3 – increment/decrement

( Example: ++i, j–, ++k )

while

while (condition)

{ statements; } where,

condition might be a>5, i<10

do while

do { statements; }

while (condition); where,

condition might be a>5, i<10

Page 7: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

while

do while

Loop is executed

only when

condition is true.

Loop is executed for first time

irrespective of the condition. After

executing while loop for first time, then

condition is checked.

Q-17: Difference Between ”while”&”do while” loops in C

language? Ans:

Q-18: What are Case control statements?

Ans: The statements which are used to execute only specific block of statements in a series of

blocks are called case control statements.

There are 4 types of case control statements in C language. They are,

Types of

Statements

Description

switch

Switch case statements are used to execute only specific case statements based on the switch expression.

break

Break statement is used to terminate the while loops, switch case loops and for loops from the subsequent execution.

continue Continue statement is used to continue the next iteration of for loop, while loop and

do-while loops. So, the remaining statements are skipped within the loop for that

particular iteration.

goto

goto statements is used to transfer the normal flow of a program to the specified

label in the program.

Page 8: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-19:What do you mean by Storage Class Specifiers?

Ans: Storage class specifiers in C language tells the

compiler where to store a variable, how to store the variable, what is the initial value of the

variable and life time of the variable.

Syntax:

storage_specifier data_type variable _name;

• ”_” represents the Space

There are 4 storage class specifiers available in C language. They are,

1. auto

2. extern

3. static

4. register

Storage Specifier Description

auto

Storage place: CPU Memory

Initial/default value: Garbage value

Scope: local

Life: Within the function only.

extern

Storage place: CPU memory

Initial/default value: Zero

Scope: Global

Life: Till the end of the main program. Variable definition might

be anywhere in the C program.

static

Storage place: CPU memory

Initial/default value: Zero

Scope: local

Life: Retains the value of the variable between different function

calls.

register

Storage place: Register memory

Initial/default value: Garbage value

Scope: local

Life: Within the function only.

Q-20:What are Arrays?

Ans: Array is a collection of variables belongings to the same data type. You can store group of

data of same data type in an array.

i.e,

• int a[10]; // integer array

Page 9: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

• char b[10]; // character array i.e. string

Page 10: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-21:What are Strings?

Ans:

• C Strings are nothing but array of characters ended with null character („\0‟).

• This null character indicates the end of the string.

• Strings are always enclosed by double quotes. Whereas, character is enclosed by single

quotes in C.

Example for C string:

• char string[20] = {„f‟, ‟r‟, „e‟, „s‟, „h‟, „2‟, „r‟, „e‟, „f‟, ‟r‟, „e‟, „s‟, „h‟, „\0‟};

(or)

• char string[20] = “fresh2refresh”;

(or)

• char string [] = “fresh2refresh”;

Q-22:What are C String functions?

Ans: String.h header file supports all the string functions in C language. All the string functions

are given below.

String

functions

Description

strcat ( ) Concatenates str2 at the end of str1

strncat ( ) Appends a portion of string to another

strcpy ( ) Copies str2 into str1

strncpy ( ) Copies given number of characters of one string to another

strlen ( ) Gives the length of str1

strcmp ( ) Returns 0 if str1 is same as str2. Returns <0 if strl < str2. Returns >0 if str1 >

str2

Q-23:What are Pointers? Ans: Pointers in C language is a variable that stores/points the address of another variable. A Pointer in C is used to allocate memory dynamically i.e. at run time. The pointer variable might

be belonging to any of the data type such as int, float, char, double, short etc.

Q-24:What are Functions? Ans: A large C program is divided into basic building blocks called C function. C function contains set of instructions enclosed by “{ }” which performs specific operation in a C program.

Actually, Collection of these functions creates a C program.

Page 11: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-25:What are uses of Functions?

Ans:

• C functions are used to avoid rewriting same logic/code again and again in a program.

• There is no limit in calling C functions to make use of same functionality wherever

required.

• We can call functions any number of times in a program and from any place in a

program.

• A large C program can easily be tracked when it is divided into functions.

• The core concept of C functions are, re-usability, dividing a big task into small pieces to

achieve the functionality and to improve understandability of very large C programs.

Q-26: What are 3 aspects in each C function ? Ans: Function declaration or prototype – This informs compiler about the function name, function parameters and return value‟s data type.

Function call – This calls the actual function

Function definition – This contains all the statements to be executed.

Q-27:Difference Between Call by Value & Call by Reference? Ans:

Call by value Call by reference

• The value of the variable is passed

to the function as parameter.

• The value of the actual parameter

can not be modified by formal

parameter.

• Different Memory is allocated for

both actual and formal parameters.

Because, value of actual parameter

is copied to formal parameter.

• The address of the variable is

passed to the function as

parameter.

• The value of the actual parameter

can be modified by formal

parameter.

• Same memory is used for both actual and formal parameters since only address is used by both parameters.

Q-28:What are User defined functions in C?

Ans: User defined functions are the functions which are written by us for our own requirement.

Q-29: What is Dynamic memory allocation in C?

Ans: The process of allocating memory during program execution is called dynamic memory

allocation.

Page 12: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-30:What is a Structure ? Ans: C Structure is a collection of different data types which are grouped together and each element in a C structure is called member.

Q-31:What is the Difference between C variable, C array and C structure?

Ans:

Variable Array Structure

A normal C variable can hold only one data of one data type

at a time.

An array can hold group of data of same data type.

A structure can hold group of data of different data types

and Data types can be int,

char, float, double and long

double etc

Q-32:What are Array of Structure? Ans: C Structure is collection of different datatypes ( variables ) which are grouped together. Whereas, array of structures is nothing but collection of structures. This is also called as structure

array in C.

Q-33:What’s the Difference between static memory allocation and dynamic memory

allocation in C?

Ans:

Static memory allocation Dynamic memory allocation

In static memory allocation, memory is allocated

while writing the C program. Actually, user requested

memory will be allocated at compile time.

In dynamic memory allocation, memory

is allocated while executing the program.

That means at run time.

Memory size can‟t be modified while execution.

Example: array

Memory size can be modified while

execution.

Example: Linked list

Q-34:What is Type Casting ?

Ans: Typecasting concept in C language is used to modify a variable from one date type to another data

type. New data type should be mentioned before the variable name or value in brackets which to be

typecast.

Q-35:What is Typedef? Ans: Typedef is a keyword that is used to give a new symbolic name for the existing name in a C program. This is same like defining alias for the commands.

Page 13: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/

Q-36:What is Union? Ans: C Union is also like structure, i.e. collection of different data types which are grouped together. Each element in a union is called member.

Q-37: Difference between structure and union in C?

Ans:

C Structure C Union

Structure allocates storage space for

all its members separately.

Union allocates one common storage space for all its

members.

Union finds that which of its member needs high storage

space over other members and allocates that much space

Structure occupies higher memory

space.

Union occupies lower memory space over structure.

We can access all members of

structure at a time.

We can access only one member of union at a time.

Q-38:What is File? Ans: File is a collection of bytes that is stored on secondary storage devices like disk. There are two kinds of files in a system. They are,

1. Text files (ASCII)

2. Binary files

Q-39:What are Basic file operations in C programming?

Ans:

1. Opening a file 2. Closing a file

3. Reading a file

4. Writing in a file

Q-40:What are some Inbuilt functions for file handling in C language?

Ans:

File handling functions Description

fopen () fopen () function creates a new file or opens an existing file.

fclose () fclose () function closes an opened file.

getw () getw () function reads an integer from file.

putw () putw () functions writes an integer to file.

fgetc () fgetc () function reads a character from file.

fputc () fputc () functions write a character to file.

gets () gets () function reads line from keyboard.

puts () puts () function writes line to o/p screen.

fgets () fgets () function reads string from a file, one line at a time.

fputs () fputs () function writes string to a file.

Page 14: (To Directly See the Answer Click on that Question ) Q-1 ... · (To Directly See the Answer Click on that Question ) Q-1: What is Pre-Processor directives? Q-2: Difference between

https://cseexamhacks.wordpress.com/