Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Chapter - Advanced C Topics, PPT, PF, Semester, Engineering

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE) PDF Download

  

Introduction

 

The slides cover the following topics:

14.1  Introduction 

14.2  Redirecting Input/Output on UNIX and DOS Systems

14.3  Variable-Length Argument Lists 

14.4  Using Command-Line Arguments 

14.5  Notes on Compiling Multiple-Source-File Programs

14.6  Program Termination with exit and atexit 

14.7  The volatile Type Qualifier 

14.8  Suffixes for Integer and Floating-Point Constants 

14.9  More on Files 

14.10  Signal Handling 

14.11  Dynamic Memory Allocation with calloc and   realloc

14.12  The Unconditional Branch: goto 

 

Advanced C topics---------------------------------------------------------------Next slide

 

14.1   Introduction

 

•Several advanced topics in this chapter
 
•Operating system specific
–Usually UNIX or DOS
 
Advanced C topics---------------------------------------------------------------Next slide
 
 
14.2   Redirecting Input/Output on UNIX and DOS Systems

 

 
•Standard I/O - keyboard and screen
–Redirect input and output
 
•Redirect symbol(<)
–Operating system feature, not a C feature
–UNIX and DOS
$ or % represents command line
–Example:

$ myProgram < input

–Rather than inputting values by hand, read them from a file
 
•Pipe command(|)
–Output of one program becomes input of another

$ firstProgram | secondProgram

–Output of firstProgram goes to secondProgram
 
Advanced C topics---------------------------------------------------------------Next slide
 
 
 14.2   Redirecting Input/Output on UNIX and DOS Systems 
 
•Redirect output (>)
–Determines where output of a program goes
–Example:

$ myProgram > myFile

•Output goes into myFile (erases previous contents)
 
•Append output (>>)
–Add output to end of file (preserve previous contents)
–Example:

$ myOtherProgram >> myFile

 

•Output is added onto the end of myFile
 
Advanced C topics---------------------------------------------------------------Next slide
 
 
14.3   Variable-Length Argument Lists
 
 
•Functions with unspecified number of arguments
–Load <stdarg.h>
–Use ellipsis(...) at end of parameter list
–Need at least one defined parameter
–Example:

double myfunction ( int i, ... );

–The ellipsis is only used in the prototype of a function with a variable length argument list
printf is an example of a function that can take multiple arguments
–The prototype of printf is defined as

int printf( const char* format, ... );

 

Advanced C topics---------------------------------------------------------------Next slide
 
 
14.3  Variable-Length Argument Lists
 
 
•Macros and definitions of the variable arguments header (stdarg.h)
va_list
 
•Type specifier, required (va_list arguments;)
va_start( arguments, other variables )
 
•Intializes parameters, required before use
va_arg( arguments, type )
 
•Returns a parameter each time va_arg is called 
 
•Automatically points to next parameter
va_end( arguments )
 
•Helps function have a normal return
 
 
Advanced C topics---------------------------------------------------------------Next slide
 
 
Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

 Advanced C topics---------------------------------------------------------------Next slide

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

Advanced C topics---------------------------------------------------------------Next slide

 

14.4   Using Command-Line Arguments

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

 Advanced C topics---------------------------------------------------------------Next slide

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

Advanced C topics---------------------------------------------------------------Next slide

 

14.5   Notes on Compiling Multiple-Source-File Programs

 

•Programs with multiple source files
 
•Function definition must be in one file (cannot be split up)
 
•Global variables accessible to functions in same file
 
•Global variables must be defined in every file in which they are used
 
•Example:
    •If integer myGlobal is defined in one file
    •To use it in another file you must include the statement

• extern int myGlobal;

extern
 •States that the variable is defined in another file
 
•Function prototypes can be used in other files without an extern statement
 
•Have a prototype in each file that uses the function
 
 
 Advanced C topics---------------------------------------------------------------Next slide
 
 
14.5   Notes on Compiling Multiple-Source-File Programs
 
•Keyword static

 

 •Specifies that variables can only be used in the file in which they are defined

 

•Programs with multiple source files
 
 •Tedious to compile everything if small changes have been made to only one file
 
 •Can recompile only the changed files
 
•Procedure varies on system
 •UNIX: make utility
 
 Advanced C topics---------------------------------------------------------------Next slide
 
14.6   Program Termination with exit and atexit
 
•Function exit
•Forces a program to terminate
•Parameters – symbolic constants EXIT_SUCCESS or EXIT_FAILURE
•Returns an implementation-defined value
•Example:

exit( EXIT_SUCCESS );

•Function atexit

atexit( functionToRun );

•Registers functionToRun to execute upon successful program termination
atexit itself does not terminate the program
•Register up to 32 functions (multiple atexit() statements)
•Functions called in reverse register order
•Called function cannot take arguments or return values
 
Advanced C topics---------------------------------------------------------------Next slide
 
Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

Advanced C topics---------------------------------------------------------------Next slide

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)
 
 
Advanced C topics---------------------------------------------------------------Next slide
 
  14.7   The volatile Type Qualifier
 
volatile qualifier
•Variable may be altered outside program
•Variable not under control of program
•Variable cannot be optimized
 
Advanced C topics---------------------------------------------------------------Next slide
 
14.8  Suffixes for Integer and Floating-Point Constants
 
•C provides suffixes for constants
unsigned integer – u or U
long integer – l or L    
unsigned long integer – ul or UL
floatf or F
long doublel or L
•Examples:

174u

467L

3451ul

•If integer constant is not suffixed type determined by first type capable of storing a value of that size (int, long int, unsigned long int)
•If floating point not suffixed of type double

 

Advanced C topics---------------------------------------------------------------Next slide
 
14.9  More on Files
 
•C can process binary files
•Not all systems support binary files
•Files opened as text files if binary mode not supported
•Binary files should be used when rigorous speed, storage, and compatibility conditions demand it
•Otherwise, text files are preferred
•Inherent portability, can use standard tools to examine data
 
•Function tmpfile
•Opens a temporary file in mode "wb+"
•Some systems may process temporary files as text files
•Temporary file exists until closed with fclose or until program terminates
 
•Function rewind
•Positions file pointers to the beginning of the file

 

Advanced C topics---------------------------------------------------------------Next slide
 

14.9  More on Files

 
•File open modes:
 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

Advanced C topics---------------------------------------------------------------Next slide

 

14.10  Signal Handling

 

•Signal
•Unexpected event, can terminate program
•Interrupts (<ctrl> c), illegal instructions, segmentation violations, termination orders, floating-point exceptions (division by zero, multiplying large floats)
 
•Function signal
•Traps unexpected events
•Header <signal.h>
•Receives two arguments a signal number and a pointer to the signal handling function
 
•Function raise
•Takes an integer signal number and creates a signal
 

Advanced C topics---------------------------------------------------------------Next slide

 

14.10  Signal Handling

 

•Signals defined in signal.h

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

Advanced C topics---------------------------------------------------------------Next slide

 

14.10  Signal Handling

 

•Signals defined in signal.h

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

Advanced C topics---------------------------------------------------------------Next slide

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

Advanced C topics---------------------------------------------------------------Next slide

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

Advanced C topics---------------------------------------------------------------Next slide

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

 

Advanced C topics---------------------------------------------------------------Next slide

 

14.11    Dynamic Memory Allocation with calloc and realloc

 

•Dynamic memory allocation
•Can create dynamic arrays
 
calloc( nmembers, size )
nmembers – number of members
size – size of each member
•Returns a pointer to a dynamic array
 
realloc( pointerToObject, newSize )
pointerToObject – pointer to the object being reallocated
newSize – new size of the object
•Returns pointer to reallocated memory
•Returns NULL if cannot allocate space
•If newSize equals 0 then the object pointed to is freed
•If pointerToObject equals 0 then it acts like malloc
 

Advanced C topics---------------------------------------------------------------Next slide

 

14.12   The Unconditional Branch: goto

 

•Unstructured programming
•Use when performance crucial
break to exit loop instead of waiting until condition becomes false
 
goto statement
•Changes flow control to first statement after specified label
•A label is an identifier followed by a colon (i.e. start:)
•Quick escape from deeply nested loop

goto start;

 

Advanced C topics---------------------------------------------------------------Next slide

 

Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

  

The document Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE) is a part of Computer Science Engineering (CSE) category.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
Are you preparing for Computer Science Engineering (CSE) Exam? Then you should check out the best video lectures, notes, free mock test series, crash course and much more provided by EduRev. You also get your detailed analysis and report cards along with 24x7 doubt solving for you to excel in Computer Science Engineering (CSE) exam. So join EduRev now and revolutionise the way you learn!
Sign up for Free Download App for Free

FAQs on Chapter - Advanced C Topics, PPT, PF, Semester, Engineering - Computer Science Engineering (CSE)

1. What are some advanced topics in C that are covered in this chapter?
Ans. Some advanced topics covered in this chapter include pointers, structures, file handling, dynamic memory allocation, and function pointers.
2. How can advanced C topics be useful for computer science engineering students?
Ans. Advanced C topics are essential for computer science engineering students as they provide a deeper understanding of the C programming language and its applications. These topics enable students to write more efficient and optimized code, work with complex data structures, and develop software that interacts with the operating system.
3. What is the significance of learning about function pointers in C?
Ans. Function pointers in C allow for greater flexibility and extensibility in programming. They enable the passing of functions as arguments to other functions, which is particularly useful in implementing callback functions, event handling, and dynamic dispatch. Understanding function pointers is crucial for developing advanced software applications.
4. How does dynamic memory allocation in C help in managing memory efficiently?
Ans. Dynamic memory allocation in C allows developers to allocate and deallocate memory during runtime. This helps in managing memory efficiently as it allows for the allocation of memory only when needed, preventing wastage of memory. It also enables the creation of data structures that can grow or shrink dynamically based on the program's requirements.
5. What are some important concepts related to file handling in C that are covered in this chapter?
Ans. The chapter covers concepts such as opening and closing files, reading and writing data to files, file positioning, error handling, and working with binary files. Understanding these concepts is crucial for performing file operations in C, which is essential in many real-world applications involving data storage and retrieval.
Download as PDF
Related Searches

pdf

,

Semester

,

Semester

,

Chapter - Advanced C Topics

,

Extra Questions

,

Important questions

,

mock tests for examination

,

Engineering - Computer Science Engineering (CSE)

,

Previous Year Questions with Solutions

,

Chapter - Advanced C Topics

,

ppt

,

practice quizzes

,

shortcuts and tricks

,

Summary

,

Semester Notes

,

Engineering - Computer Science Engineering (CSE)

,

PF

,

PPT

,

Engineering - Computer Science Engineering (CSE)

,

Chapter - Advanced C Topics

,

PPT

,

past year papers

,

PF

,

Exam

,

PF

,

study material

,

Free

,

Semester

,

video lectures

,

MCQs

,

Viva Questions

,

PPT

,

Objective type Questions

,

Sample Paper

;