C Programming

A collection of 30 Articles

Compile C program with gcc compiler on Bash on Ubuntu on Windows 10

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. You can compile a C program by using the gcc command in Windows 10 Bash on Ubuntu. 1.Enable Bash on Ubuntu on Windows 10 If you don't have a enable Ubuntu ...

Graphics (graphics.h) - C Programming

Graphics programming in C used to drawing various geometrical shapes(rectangle, circle eclipse etc), use of mathematical function in drawing curves, coloring an object with different colors and patterns and simple animation programs like jumping ball and moving cars. 1. First graphics program (Draw a line) #include<graphics.h& ...

Preprocessor Directives - C Programming

The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation (Proprocessor direcives are executed before compilation.). It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs. A macro ...

Difference between C and Ansi C

Main difference: C was originally developed by Dennis Ritchie at AT&T Bell Labs between 1969 and 1973. It has a free-format program source code. C is a general-purpose programming language. C is one of the oldest currently used programming languages and is one of the most widely used ...

What does the C ??!??! operator do?

??! is a trigraph that translates to |. So it says: if(a || b){ ... }else{ ... } So, what is digraphs and trigraphs? In computer programming, digraphs and trigraphs are sequences of two and three characters, respectively, that appear in source code and, according to a programming language specification, should be treated as if ...

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, "a" ...

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; /* 4 bytes ...

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 ...

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] ...