Skip to main content

Posts

Showing posts with the label Cpp Advanced

C++ Dynamic Memory Allocation

C++ Advanced C++ Dynamic Memory Allocation Often some situation arises in programming where data or input is dynamic in nature, i.e. the number of data item keeps changing during program execution. A live scenario where program is developed to process lists of employees of an organization. The list grows as the names are added and shrinks as the names get deleted. With the increase in name the memory allocate space to the list to accommodate additional data items. Such situations in programming require  dynamic memory management  techniques. In this chapter you will learn about how to dynamically allocate memory within a C++ program. What is memory Allocation? There are two ways via which memories can be allocated for storing data. The two ways are: Compile time allocation or static allocation of memory: where the memory for named variables is allocated by the compiler. Exact size and storage must be known at compile time and for array declaration the size has to be constant. ...

C++ Signal Handling

C++ Signal Handling Signals are interrupts of software which is delivered to a process by the operating system. Signals can also be issued by the OS on the basis of system or error condition. Programmers can generate interrupts by pressing Ctrl+C on a UNIX, LINUX, Mac OS X or Windows system. There is some default behavior for some but in this chapter, you will learn about how to handle the signals and manage them properly. Some signals are there which cannot be caught by the program but there is the list of signals which programmers can in the program and take adequate actions based on the signal. The signals are defined  <csignal>  header file. Here is a lists of signals along with their description and working capability: SIGABRT : It is used for Abnormal termination of the program, such as a call to abort SIGFPE : an erroneous arithmetic operation, such as a divide by zero or an operation resulting in overflow. SIGILL : It is used for detecting an illegal instruction ...

C++ Namespace

C++ Namespace Let’s take a situation where there are two students with the same name in an institution.  Then we have to differentiate them in a different manner and more likely we have to add some more information along with their name, like roll number or parents name or email address. Same situation may arise in C++ programming also where you might write some code having function name  i.e.  fun()  and there is already existing another library having same function name. This makes the compiler halt down and left it with no way to know which of these two function to use within the C++ program. Namespaces are used to solve this situation. What are Namespaces? Namespaces provides a scope for identifiers (variables, functions etc) within own declarative region. Namespaces are used to systematize code in logical groups which prevents naming conflict, which can occur especially if there are multiple libraries with single names in your code base....

C++ Exception Handling

C++ Exception Handling It’s very rare that a large program or software works correctly first time. It might have errors. The two most common types of errors are: Logical errors Syntactic errors Programmers can debug these errors by exhausting debugging and testing procedures. But programmers often come across some peculiar problems in addition logic or syntax errors. These types of errors are known as exceptions. Exceptions are run-time anomalies or unusual logical conditions that may come up while executing the C ++ program. In this chapter you will learn about these anomalies and how to handle these anomalies within a C++ program. What is exception handling? Exceptions allow a method to react to exceptional circumstances and errors (like runtime errors) within programs by transferring control to special functions called handlers. For catching exceptions, a portion of code is placed under exception inspection. Exception handling was not a part of the original C++. It is a new feature ...

C++ Preprocessor

C++ Preprocessor Preprocessor directives are one of the unique features of C++. It provides many tools that other high-level language does not, and programmers can use these tools to create efficient, easy-to-read, easy-to-modify and portable C ++ programs. Before a C++ program gets compiled by the compiler, the source-code gets processed by the compiler. This technique is called preprocessor and the process is called preprocessing. It is separate program part that the C++ compiler invokes it at the first part of the translation. This technique is not a part of the compiler but it is a separate method that comes under compilation process. It directs the compiler that the information should be preprocessed before the actual compilation starts. All preprocessor directives in C++ begin with #, and they do not need to end with a semicolon(;) because this is not a statement in C++. The #define directive creates a symbolic constants and these symbolic constants are called macro. The general ...

For Programs Click Here