Primary Why in C language is it the case that a[5] == 5[a]? The C standard defines the Array Subscript Operator [] as follows: a[b] == *(a + b) Therefore a[5] will evaluate to: *(a + 5) and 5[a] will evaluate to: *(5 + a) and from elementary math we know those are equal. This is the direct artifact of arrays behaving as pointers, "...
Primary Why isn't sizeof for a struct equal to the sum of sizeof of each member? This is because of padding added to satisfy alignment constraints. Data structure alignment impacts both performance and correctness of programs. Here's an example using typical settings for an x86 processor (all used 32 and 64 bit modes): struct X { short s; /* 2 bytes */ /* 2 padding bytes */ int i;...
Primary Why is one loop so much slower than two loops? Suppose a1, b1, c1, and d1 point to heap memory and code has the following loop. const int n=100000; for(int j=0;j<n;j++){ a1[j] += b1[j]; c1[j] += d1[j]; } This loop is executed 10,000 times via another outer for loop. To speed...
Primary Why is processing a sorted array faster than an unsorted array? Here is a piece of Visual C++ code that seems very peculiar. For some strange reason, sorting the data miraculously makes the code almost six times faster. #include <algorithm> #include <ctime> #include <iostream> int main() { // Generate data const unsigned arraySize = 32768; int data[arraySize]...
Primary What is the difference between #include <filename> and #include “filename”? The difference is in the location where the preprocessor searches for the included file. For #include "filename" the preprocessor searches in the same directory as the file containing the directive. This method is normally used to include programmer-defined header files. For #include <filename> the preprocessor searches...
Primary What are the differences between a pointer variable and a reference variable? * A pointer can be re-assigned: int x = 5; int y = 6; int *p; p = &x; p = &y; *p = 10; assert(x == 5); assert(y == 10); A reference cannot, and must be assigned at initialization: int x = 5; int y = 6; int &r = x; * A pointer has its...
Primary What is the name of the "-->" operator? Here's an example: #include <stdio.h> int main() { int x = 10; while( x --> 0 ) // x goes to 0 { printf("%d ", x); } } Answer --> is not an operator. It is in fact two separate operators, -- and >. The conditional's...
Primary Quiz - Loops (for, while, do while, break, continue and goto) in C Programming This quiz is based on this Loops in C [https://developerinsider.co/2016/03/28/the-loop-control-structure-c-programming/] tutorial including introduction to for loop, while loop, do while loop, break, continue statement, and goto. So, To get better score on quiz, read the tutorial first. Poll Maker [http://www.poll-maker.com]...
Primary Turbo C++ IDE Shortcuts S.No.Shortcuts keysAction1F1For Help2.F2Save3.F3Open4.F4Go to cursor5.F5Zoom6.F6 Next7.F7Trace into8.F8Step over9.F9Make10.F10Menu11.Alt+XQuit12.Alt+BkspUndo13. Shift+Alt+BkspRedo14.Shift+DelCut15.Ctrl+InsCopy16.Shift+InsPaste17.Ctrl+Del Clear18.Ctrl+LSearch again19.Alt+F7Previous error20.Alt+F8Next error21.Ctrl+F9 'or' Alt+...
Primary Quiz - Decision Control, Expression and Operators in C This quiz is based on the and Expression & Operators Precedence [https://developerinsider.co/2016/03/28/expression/] and The Decision Control Structure [https://developerinsider.co/2016/03/28/the-decision-control-structure-c-programming/] tutorial. So, To get better score on quiz, read the tutorial first. Poll Maker [http://www.poll-maker.com]...
Primary Quiz - Introduction to C Programming This quiz is based on this Introduction to C Programming [https://developerinsider.co/2016/03/28/introduction-c-programming/] tutorial. So, To get better score on quiz, read the tutorial first. Poll Maker [http://www.poll-maker.com]...
Downloads Download Turbo C++ for Windows 7, 8, 8.1, 10 and Windows 11 (32-64 bit) with full/window screen mode and many more extra features 1. How to install Turbo C++ Step 1 Download Turbo C++ 3.2 from here Download Turbo C++ Step 2 If any previous version of "Turbo C++" is installed on your computer, then first of all uninstall that. Step 3 Extract the downloaded "Turbo C++ 3.2....
Primary Command Line Arguments - C Programming The arguments that we pass on to main() at the command prompt are called command line arguments. The full declaration of main looks like this: int main (int argc, char *argv[]) The function main() can have two arguments, traditionally named as argc and argv . Out of these, argv is an...
Primary C Programming Language Cheat Sheet 1. C Programming 1.1 What is C? * C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972 by Dennis Ritchie. * Any programming Language can be divided in to two categories. * Problem oriented (High level language) * Machine oriented (Low level language) But C...
Primary Strings - C Programming 1. What is String? Strings are arrays of characters. Each member of array contains one of characters in the string. Example #include<stdio.h> main() { char name[20]; printf("Enter your name : "); scanf("%s",name); printf("Hello, %s , how are you ?\n"...