
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2677 of 3366

500 Views
Here we will see how to generate the preprocessed or preprocessor code from the source code of a C or C++ program.To see the preprocessed code using g++ compiler, we have to use the ‘-E’ option with the g++.Preprocessor includes all of the # directives in the code, and also expands the MACRO function.Syntaxg++ -E program.cppExample#define PI 3.1415 int main() { float a = PI, r = 5; float c = a * r * r; return 0; }Output$ g++ -E test_prog.cpp int main() { float a = 3.1415, r = 5; float c = a * r * r; return 0; }

6K+ Views
Here we will see how the C programs are executed in a system. This is basically the compilation process of a C program.The following diagram will show how a C Source Code can be executed.In the above diagram there are different steps −C Code − This is the code that you have written. This code is sent to the Preprocessors section.Preprocessing − In this section the preprocessor files are attached with our code. We have use different header files like stdio.h, math.h etc. These files are attached with the C Source code and the final C Source generates. (‘#include’, ‘#define’ ... Read More

315 Views
One of the most frequent question is what will be the value of some uninitialized primitive data values in C or C++? Well the answer will be different in different systems. We can assume the compiler will assign 0 into the variables. It can be done for integer as 0, for float 0.0, but what will be for character type data?Example#include using namespace std; main() { char a; float b; int c; double d; long e; cout

6K+ Views
In C or C++, we can use the constant variables. The constant variable values cannot be changed after its initialization. In this section we will see how to change the value of some constant variables.If we want to change the value of constant variable, it will generate compile time error. Please check the following code to get the better idea.Example#include main() { const int x = 10; //define constant int printf("x = %d", x); x = 15; //trying to update constant value printf("x = %d", x); }Output[Error] assignment of read-only variable 'x'So this is generating ... Read More

2K+ Views
In this section we will see what are the differences between macros and functions in C. The macros are pre-processed, so it means that all the macros will be preprocessed while it is compiled. The functions are not preprocessed, but compiled.In macros no type checking is done, so it may occur some problems for different types of inputs. In the case of functions, this is not done. Also for macros if the inputs are not properly maintained, then it may generate some invalid results. Please check the following program to get the idea about the problem.Example#include #define SQUARE(x) x ... Read More

7K+ Views
Here we will see how to generate assembly language output from C or C++ source code using gcc.The gcc provides a great feature to get all intermediate outputs from a source code while executing. To get the assembler output we can use the option ‘-S’ for the gcc. This option shows the output after compiling, but before sending to the assembler. The syntax of this command is like below.gcc –S program.cppNow, let us see how to output will be look like. Here we are using a simple program. In this program two numbers are stored into the variables x and ... Read More

2K+ Views
The free() function is used to deallocate memory while it is allocated using malloc(), calloc() and realloc(). The syntax of the free is simple. We simply use free with the pointer. Then it can clean up the memory.free(ptr);The free() is not taking any size as parameter, but only pointer. So the question comes, that how the free() function know about the size of the block to deallocate?When we use the dynamic memory allocation techniques for memory allocations, then this is done in the actual heap section. It creates one word larger than the requested size. This extra word is used ... Read More

613 Views
In this section we will see what is the compound literals in C. The compound literals are introduced in C99 standard in C. Using this feature, it can create unnamed objects. In the following example we will see how to use compound literal to generate object without any name.Example#include struct point { int x; int y; }; void display_point(struct point pt) { printf("(%d,%d)", pt.x, pt.y); } main() { display_point((struct point) {10, 20}); }Output(10,20)

4K+ Views
A structures (or struct) is a user-defined data type, which is used to group and store variables of different data types inside a single name. But in C, structures can store only data members whereas C++ can store member functions, constructors, destructors, and even inheritance which is similar to classes in C++, but the only difference between struct and classes is that struct members are public by default. In this following article we will see how structure differs in both C and C++ in detail. Structures in C The structures in C is a user-defined data type, which is used ... Read More

2K+ Views
A structure in C++ is a user-defined data type, which is used to group and store variables of different data types under a single name. In this article we will see how to sort an array of structures using conditions on member variables. For this we will be using the sort() function which is defined under header file. Syntax Here is the following syntax of sort() function. sort(start_index, end_index, comparison_function); start_index is an iterator (or pointer) to the first element of the array of structures.end_index is an iterator (or pointer) to one past the last element (means last_index + ... Read More