C code to dynamically allocate one, two and three dimensional arrays (using malloc())

One Dimensional Array int \*myarray = malloc(no\_of\_elements \* sizeof(int)); //Access elements as myarray\[i\] 2 Dimensional Array Method1 int \*\*myarray = (int \*\*)malloc(nrows \* sizeof(int \*)); for(i = 0; i < nrows; i++) { myarray\[i\] = malloc(ncolumns \* sizeof(int)); //allocating 1 D array = number of elements in column } // Access elements as myarray\[i\]\[j\] Method 2 (Contagious Allocation) int \*\*myarray = (int \*\*)malloc(nrows \* sizeof(int \*)); myarray\[0\] = malloc(nrows \* ncolumns \* sizeof(int)); for(i = 1; i < no\_of\_rows; i++) myarray\[i\] = myarray\[0\] + (i \* ncolumns); // Access elements as myarray\[i\]\[j\] In either case, the elements of the dynamic array can be accessed with normal-looking array subscripts: array[i][j]. [Read More]

What is a dangling pointer? What are reference counters with respect to pointers?

A pointer which points to an object that no longer exists. Its a pointer referring to an area of memory that has been deallocated. Dereferencing such a pointer usually produces garbage. Using reference counters which keep track of how many pointers are pointing to this memory location can prevent such issues. The reference counts are incremented when a new pointer starts to point to the memory location and decremented when they no longer need to point to that memory. [Read More]

To add two long positive numbers (each represented by linked lists in C)

Problem You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list. EXAMPLE Input: (3 -> 1 -> 5) + (5 -> 9 -> 2) Output: 8 -> 0 -> 8 [Read More]

Operator Precedence in C & CPP

Operator Precedence Chart Operator Type Operator Associativity 1. Primary Expression Operators () [] . -> expr++ expr– left-to-right 2. Unary Operators * & + - ! ~ ++expr –expr right-to-left (typecast) sizeof() 3. Binary Operators * / % left-to-right + - » « < > <= >= == != & ^ | && || 4. Ternary Operator ?: right-to-left 5. Assignment Operators = += -= *= /= %= »= right-to-left [Read More]

What's Database Normalization ?

Normalization is the process where a database is designed in a way that removes redundancies, and increases the clarity in organizing data in a database. In easy English, it means take similar stuff out of a collection of data and place them into tables. Keep doing this for each new table recursively and you’ll have a Normalized database. From this resultant database you should be able to recreate the data into it’s original state if there is a need to do so. [Read More]

What's an RDBMS ?

This concept was first described around 1970 by Dr. Edgar F. Codd in an IBM research publication called “System R4 Relational”. A relational database uses the concept of linked two-dimensional tables which comprise of rows and columns. A user can draw relationships between multiple tables and present the output as a table again. A user of a relational database need not understand the representation of data in order to retrieve it. [Read More]

Types of Databases

Database Classification can be done in 2 ways: 1) On Browsing and Manipulating One way to classify different types of databases is by their function: Analytic Databases Analytic databases (a.k.a. OLAP- On Line Analytical Processing) are primarily static, read-only databases which store archived, historical data used for analysis. For example, a company might store sales records over the last ten years in an analytic database and use that database to analyze marketing strategies in relationship to demographics. [Read More]

What is a Database?

A database is a collection of data. A database could be as simple as a text file with a list of names. Or it could be as complex as a large, relational database management system, complete with in-built tools to help you maintain the data. Before we get into dedicated database management systems, let’s start with the basics - let’s look at a simple text file example. Or it may have rows and columns facility like in spreadsheet. [Read More]

Acronyms used in operating system

A/UX - Apple UniX AIX - Advanced Interactive eXecutive BSD - Berkeley Software Distribution CIMOM - Common Information Model Object Manager DAT - Direct Address Translation DSI - Dynamic System Initiative FAT - File Allocation Table GPO - Group Policy Object HKCC - HKEY_CURRENT_CONFIG HKCR - HKEY_CLASSES_ROOT HKCU - HKEY_CURRENT_USER HKLM - HKEY_LOCAL_MACHINE HPUX - Hewlett Packard UniX JCL - Job Control Language Linux - Linus and Unix LM - LAN Manager [Read More]