Showing posts with label c. Show all posts
Showing posts with label c. Show all posts

Saturday, 3 October 2026

Difference Between Stack and Heap Memory: Stack vs Heap Explained

Difference Between Stack and Heap Memory: Stack vs Heap Explained

Stack and heap are two important areas associated with memory management during program execution. They are commonly discussed in operating systems, C, C++, Java, and other programming environments. Stack memory is generally used for function-call information and automatic storage, while heap memory is used for dynamically allocated objects and data. Their allocation method, lifetime, management, size characteristics and performance are different.

Table of Contents

Sunday, 4 January 2015

Difference between C and C++


Sr. No.
CLanguage
C++ Language
1
C is a procedural programming Language.
C++ is a multi-paradigm
language which means it is procedural as well as object
oriented language.
2
In C, importance is given to the steps or procedure of the program.
C++ focuses on the data rather than the process.
3
Data is not secure because oops feature such as data hiding etc. are not present in C.
Data is secure because it supports oops concepts.
4
C is a low-level Language.
It is Middle level Language.
5
C uses the top-down approach .Program is formulated step by step,
each step is processed into detail.
C++ uses the bottom-up approach. In C++ base elements are

Thursday, 11 April 2013

Difference Between Structure and Union



Characteristics
Structure
Union
Definition
A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure.
A union is a special data type that enables to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time
Declaration
typedef struct {
          char name[64];
          char course[128];
          int age;
          int year;
  } student;
union Data
{
   int i;
   float f;
   char  str[20];
} data;  
Memory Allocation
In a structure, all of its data members are stored in contiguous memory locations. The size of an object of a struct is, therefore, the size of the sum of all its data members.

Example for Structure:

struct tech
{
char p;
int x;
float Q;
int y;
}D;

memory allocated for D will be  1+2+4+2= 9 bytes

A union is a class all of whose data members are mapped to the same address within its object. The size of an object of a union is, therefore, the size of its largest data member.