Unit 2

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

Click on Subject/Paper under Semester to enter.

Probability and Environmental Sciences


Professional English complex function - and Sustainability -
Professional English - - II - HS3252 MA3303 GE3451
I - HS3152
Statistics and Electromagnetic Transmission and
Matrices and Calculus Numerical Methods - Theory - EE3301 Distribution - EE3401

4th Semester
3rd Semester

- MA3151 MA3251
1st Semester

2nd Semester

Digital Logic Circuits - Linear Integrated


Engineering Physics - Engineering Graphics EE3302 Circuits - EE3402
PH3151 - GE3251
Measurements and
Electron Devices and Instrumentation -
Engineering Chemistry Physics for Electrical Circuits - EC3301 EE3403
- CY3151 Engg - PH3202
Microprocessor and
Electrical Machines I - Microcontroller -
Basic Civil and
EE3303 EE3404
Problem Solving and Mechanical Engg -
Python Programming - BE3255
C Programming and Electrical Machines II
GE3151
Electric Circuit Data Structures - - EE3405
Analysis - EE3251 CS3353

Power System Analysis


High Voltage
- EE3501
Engineering - EE3701
Protection and
Switchgear - EE3601
Power Electronics - Human Values and
5th Semester

EE3591 Ethics - GE3791


8th Semester
7th Semester
6th Semester

Power System
Operation and Control
Control Systems - - EE3602 Open Elective 2
EE3503 Project Work /
Open Elective-1
Open Elective 3 Intership
Elective 1 Elective-4
Open Elective 4
Elective 2 Elective-5
Elective 7
Elective 3 Elective-6
Management Elective
All EEE Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Circuit Theory Digital Logic Circuits Electromagnetic Theory
Environmental Science and Linear Integrated Circuits Discrete Time Systems and
Engineering and Applications Signal Processing
Electronic Devices and Electrical Machines I Electrical Machines II
Circuits
Power Plant Engineering Special Electrical Machines Transmission and Distribution
Power System Analysis Control Systems Power Electronics
Power System Operation Measurements and Design of Electrical Machines
and Control Instrumentation
Communication Engineering Solid State Drives Embedded Systems
Power Quality High Voltage Engineering Protection and Switchgear
Flexible AC Transmission Microprocessors and Electric Energy Generation,
Systems Microcontrollers Utilization and Conservation
Professional Ethics in Physics for Electronics Basic Civil and Mechanical
Engineering Engineering Engineering
Transforms and Partial Environmental Science and Problem Solving and Python
Differential Equations Engineering Programming
Engineering Physics Engineering Chemistry Numerical Methods
Engineering Graphics Technical English Object Oriented Programming
Principles of Management Total Quality Management
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

BE- Electrical and Electronics Engineering


&
BE- Electronics and Communication Engineering

Anna University Regulation: 2021

CS3353 - C Programming and Data Structures

II Year/III Semester

Question Bank

Unit- II C PROGRAMMING-ADVANCED FEATURES

Prepared By,

Ms. S. Abarna, AP/CSE

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures

UNIT II C PROGRAMMING - ADVANCED FEATURES


Structures – Union – Enumerated Data Types – Pointers: Pointers to Variables, Arrays and
Functions– File Handling – Preprocessor Directives

UNIT-II / PART-A
1. What is a Pointer? How a variable is declared to the pointer?
Pointer is a variable which holds the address of another variable.
Pointer Declaration: datatype *variable-name;
Example: int *x, c=5; x=&a;
2. What are the uses of Pointers?
Pointers are used to return more than one value to the function, Pointers are more
efficient in handling the data in arrays, Pointers reduce the length and complexity of the
program, They increase the execution speed, The pointers saves data storage space in
memory
3. What are * and & operators means?
„*‟ operator means „value at the address‟ „&‟ operator means „address of‟
4. What is meant by Preprocessor?
Preprocessor is the program, that process our source program before the compilation.
5. How can you return more than one value from a function?
A Function returns only one value. By using pointer we can return more than one value.
6. Is it possible to place a return statement anywhere in „C‟ program?
Yes. The return statement can occur anywhere.
7. What is the difference between an array and pointer?
Array Pointer

Array allocates space automatically. Pointer is explicitly assigned to point to an


allocated space.
It cannot be resized. It can be resized using
realloc (),
It cannot be reassigned, Size of(array Pointers can be reassigned, Sezeof(pointer
name) gives the number of bytes occupied name) returns the number of bytes used to
by the array. store the pointer variable.
8. What is dangling pointer?
In C, a pointer may be used to hold the address of dynamically allocated. Memory After
this memory is freed with the free() function, the pointer itself will still contain the
address of the released block. This is referred to as a dangling pointer. Using the pointer
in this state is a serious programming error. Pointer should be assigned NULL after
freeing memory to avoid this bug.
9. Is using exit() the same as using return?
No. The exit() function is used to exit your program and return control to the operating
system. The return statement is used to return from a function and return control to the
calling function. If you issue a return from the main() function, you are essentially
returning control to the calling function, which is the operating system. In this case, the
return statement and exit() function are similar.
10. What is stack trace?
A "stack trace" is a list of which functions have been called, based on this information.
When you start using a debugger, one of the first things you should learn is how to get a
stack trace. The stack is very inflexible about allocating memory; everything must be
deallocated in exactly the reverse order it was allocated in.
8

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


11. What is the difference between NULL and NUL?
NUL is the name of the first character in the ASCII character set. It corresponds to a zero
value. There's no standard macro NUL in C, but some people like to define it. NULL can
be defined as ((void*)0), NUL as '\0'. Both can also be defined simply as 0. If they're
defined that way, they can be used interchangeably.
12. What is a "null pointer assignment" error? What are bus errors, memory faults, and
core dumps?
Null pointer assignment is a message you might get when an MS-DOS program finishes
executing. Some such programs can arrange for a small amount of memory to be
available "where the NULL pointer points to" (so to speak). If the program tries to write
to that area, it will overwrite the data put there by the compiler. When the program is
done, code generated by the compiler examines that area. If that data has been changed,
the compiler-generated code complains with null pointer assignment.
13. Write the syntax for including functions?
The syntax for including functions in program is
return_type function_name(datatype var1, datatype var2,…);
//FUNCTION DECLARATION
int main()
{
variable_name = function_name(var1, var2, …);
//FUNCTION CALL
…..
Return 0;
}
return_type function_name(datatype var1, datatype var2,…)
//FUNCTION DEFINITION
{
…..
statements
……
return(variable);
}
14. What is Pointer Arithmetic?
A pointer is an address, which is a numeric value. Therefore, you can perform
arithmetic operations on a pointer just as you can on a numeric value. There are four
arithmetic operators that can be used on pointers: ++, --, +, and -.
15. How does free() know how much memory to release?
There's no standard way. It can vary from compiler to compiler, even from version to
version of the same compiler. free(), malloc(), calloc(), and realloc() are functions; as long
as they all work the same way, they can work any way that works.
16. Can math operations be performed on a void pointer?
No. Pointer addition and subtraction are based on advancing the pointer by a number of
elements. By definition, if you have a void pointer, you don't know what it's pointing to,
so you don't know the size of what it's pointing to. If you want pointer arithmetic to
work on raw addresses, use character pointers.
17. What is a void pointer?
A void pointer is a C convention for "a raw address." The compiler has no idea what
type of object a void pointer "really points to." If you write
int *ip;
ip points to an int. If you write void *p; p doesn't point to a void!
9

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


18. What is indirection?
If p is a pointer, the value of p is the address of the object. *p means "apply the indirection
operator to p"; its value is the value of the object that p points to. *p is an lvalue; like a
variable, it can go on the left side of an assignment operator, to change the value. If p is a
pointer to a constant, *p is not a modifiable lvalue; it can't go on the left
side of an assignment.
19. What is the difference between far and near pointers?
Compilers for PC compatibles use two types of pointers.
 near pointers are 16 bits long and can address a 64KB range. far pointers are 32 bits
long and can address a 1MB range.
 near pointers operate within a 64KB segment. There's one segment for function
addresses and one segment for data.
20. What do you mean by array of pointers?
 An array of pointers is an indexed set of variables in which the variablesare
pointers (a reference to a location in memory).
 Pointers are an important tool for creating, using, and destroying all types of data
structures.
Example: int *ptr[10];
The above statement declares array of an array of 10 pointers where each of the pointer
points to an integer variable.
21. How do you use a pointer to a function?
The hardest part about using a pointer-to-function is declaring it. Consider an example.
You want to create a pointer, pf, that points to the strcmp() function. The strcmp()
function is declared in this way:
int strcmp( const char *, const char * )
22. List the advantage of recursion. (May 18)
 Reduce unnecessary calling of function.
 Through Recursion one can Solve problems in easy way while its iterative solution is
very big and complex.For example to reduce the code size for Tower of Honai
application, a recursive function is bet suited.
 Extremely useful when applying the same solution.
23. What is the need for functions? (May 19)
Functions are used because of following reasons
 To improve the readability of code.
 Improves the reusability of the code, same function can be used in any program
rather than writing the same code from scratch.
 Debugging of the code would be easier if you use functions, as errors are easy to be
traced.
 Reduces the size of the code, duplicate set of statements are replaced by function calls.

24. List some preprocessor directives in C.(Jan14, 16)


 Macro Replacement Directive (#define,#undef)
 Source File Inclusion Directive (#include)
 Line Directive (#line)
 Error Directive (#error)
25. What is meant by Preprocessor Directives?
 Preprocessor is controlled by directives (commands) known as Preprocessor Directives
 Preprocessor directives are not part of C language
 It consists of various preprocessing tokens
 Begins with pound symbol(#)
10

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


26. Give the rules for defining preprocessor.
 # pound symbol used before preprocessor directive
 # must be first character in source file or first non white space character in a line
 New line character ends preprocessor directive
 Only single space/tab space allowed between preprocessing tokens
 Can appear anywhere in program but generally paced in beginning of program
The preprocessor cannot have termination with semicolon.
27. What is the output of the following code fragment? (May 19)
int =456, *p1, **p2;
p1=&x;
p2=&p1;
printf(“Value of x is: %d\n”, x);
printf(“Value of *p1 is: %d\n”, *p1);
printf(“Value of *p2 is: %d\n”, *p2);
Output:
Value of x is: 456
Value of *p1 is: 456
Value of *p2 is: 1640617564
28. What is the use of pre-processor directives? (May 14,15, 19)
 It makes programs easier to develop,
 easier to read,
 easier to modify
 C code more transportable between different machine architectures.
29. What is the use of #define processor? (Dec 14)
#define directive is used to define Macros –which are tokens that can be replaced foruser
defined sequence of characters
Syntax: #define macro-name replacement-list
Example: #define PI 3.14

11

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com
4931_Grace College of Engineering, Thoothukudi

CS3353- C Programming and Data Structures


UNIT-II / PART-B
1. When is a null pointer used? (May 18)
2. What do you mean by Call by reference? Explain with an example.
3. What do you mean by Call by Value? Explain with an example.
4. Write a „C‟ Program to interchange two values using call by reference (or)
What is pass by reference? Explain swapping of 2 values using pass by reference in „C‟.
(May 19)
5. Can you subtract pointers from each other? Why would you?
6. How do you use a pointer to a function? When would you use a pointer to a function?
7. Write a C program to generate Fibonacci series using function.
8. Write a C Program to find factorial of a given number using recursive function.
9. What is Pointer? How to pass pointer as an argument in function?
10. How can you pass an array to a function by value?
11. Explain the use of pointers in array handling with an example. (Nov 07)
12. Write a function using pointers to add matrix and to return the resultant matrix to the
calling function. (May 08)
13. (i) Explain the purpose of a function prototype. And specify the difference between the
user defined function and built-in function (May 18)
(ii) Write the C program to find the value of sin(x) using the series up to the givenaccuracy
(without using user defined function) also print sin(x) using library function.
(May 18)
14. (i) What is difference between pass by value and pass by reference? Write the C codingfor
swapping two numbers using pass by reference. (May 18)
(ii) What is recursion? Explain the procedure to compute sin(x) using recursive
functions. Write a C code for the same. (May 19)
15. When is a null pointer used? (May 18)

12

CS3353_CPDS

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
Click on Subject/Paper under Semester to enter.
Random Process and Electromagnetic
Professional English Linear Algebra -
Professional English - - II - HS3252 Fields - EC3452
MA3355
I - HS3152
C Programming and Networks and
Statistics and
Data Structures - Security - EC3401
Matrices and Calculus Numerical Methods -
CS3353
- MA3151 MA3251
1st Semester

3rd Semester

Linear Integrated

4th Semester
2nd Semester

Signals and Systems - Circuits - EC3451


Engineering Physics - Engineering Graphics
- GE3251 EC3354
PH3151 Digital Signal
Processing - EC3492
Physics for Electronic Devices and
Engineering Chemistry Electronics Engg - Circuits - EC3353
- CY3151 PH3254 Communication
Systems - EC3491
Control Systems -
Basic Electrical & EC3351
Problem Solving and Instru Engg - BE3254 Environmental
Python Programming - Sciences and
GE3151 Digital Systems Design Sustainability -
Circuit Analysis - - EC3352 GE3451
EC3251

Wireless
Communication -
EC3501 Embedded Systems
and IOT Design -
ET3491
VLSI and Chip Design
5th Semester

- EC3552 Human Values and


7th Semester

8th Semester
6th Semester

Artificial Intelligence Ethics - GE3791


and Machine Learning
Transmission Lines and - CS3491
RF Systems - EC3551 Open Elective 2 Project Work /
Intership
Open Elective-1 Open Elective 3
Elective 1
Elective-4
Open Elective 4
Elective 2
Elective-5
Elective 3
Elective-6
All ECE Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Circuit Analysis Digital Electronics Communication Theory
Basic Electrical and Electrical Engineering and Principles of Digital
Instrumentation Engineering Instrumentation Signal Processing
Electronic Devices Linear Integrated Circuits Signals and Systems
Electronic Circuits I Electronic Circuits II Digital Communication
Transmission Lines and Wave Control System Engineering Microprocessors and
Guides Microcontrollers
Computer Architecture Computer Networks Operating Systems
RF and Microwave Engineering Medical Electronics VLSI Design
Optical Communication and Embedded and Real Time Cryptography and
Networks Systems Network Security
Probability and Random Transforms and Partial Physics for Electronics
Processes Differential Equations Engineering
Engineering Physics Engineering Chemistry Engineering Graphics
Problem Solving and Python Object Oriented Programming Environmental Science
Programming and Data Structures and Engineering
Principles of Management Technical English Total Quality
Management
Professional Ethics in Engineering Mathematics I Engineering Mathematics
Engineering II
Click on Subject/Paper under Semester to enter.
Probability and Environmental Sciences
Professional English complex function - and Sustainability -
Professional English - - II - HS3252 MA3303 GE3451
I - HS3152
Statistics and Electromagnetic Transmission and
Matrices and Calculus Numerical Methods - Theory - EE3301 Distribution - EE3401

4th Semester
3rd Semester

- MA3151 MA3251
1st Semester

2nd Semester

Digital Logic Circuits - Linear Integrated


Engineering Physics - Engineering Graphics EE3302 Circuits - EE3402
PH3151 - GE3251
Measurements and
Electron Devices and Instrumentation -
Engineering Chemistry Physics for Electrical Circuits - EC3301 EE3403
- CY3151 Engg - PH3202
Microprocessor and
Electrical Machines I - Microcontroller -
Basic Civil and
EE3303 EE3404
Problem Solving and Mechanical Engg -
Python Programming - BE3255
C Programming and Electrical Machines II
GE3151
Electric Circuit Data Structures - - EE3405
Analysis - EE3251 CS3353

Power System Analysis


High Voltage
- EE3501
Engineering - EE3701
Protection and
Switchgear - EE3601
Power Electronics - Human Values and
5th Semester

EE3591 Ethics - GE3791


8th Semester
7th Semester
6th Semester

Power System
Operation and Control
Control Systems - - EE3602 Open Elective 2
EE3503 Project Work /
Open Elective-1
Open Elective 3 Intership
Elective 1 Elective-4
Open Elective 4
Elective 2 Elective-5
Elective 7
Elective 3 Elective-6
Management Elective
All EEE Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Circuit Theory Digital Logic Circuits Electromagnetic Theory
Environmental Science and Linear Integrated Circuits Discrete Time Systems and
Engineering and Applications Signal Processing
Electronic Devices and Electrical Machines I Electrical Machines II
Circuits
Power Plant Engineering Special Electrical Machines Transmission and Distribution
Power System Analysis Control Systems Power Electronics
Power System Operation Measurements and Design of Electrical Machines
and Control Instrumentation
Communication Engineering Solid State Drives Embedded Systems
Power Quality High Voltage Engineering Protection and Switchgear
Flexible AC Transmission Microprocessors and Electric Energy Generation,
Systems Microcontrollers Utilization and Conservation
Professional Ethics in Physics for Electronics Basic Civil and Mechanical
Engineering Engineering Engineering
Transforms and Partial Environmental Science and Problem Solving and Python
Differential Equations Engineering Programming
Engineering Physics Engineering Chemistry Numerical Methods
Engineering Graphics Technical English Object Oriented Programming
Principles of Management Total Quality Management

You might also like