Reference for Linux ERROR CODE TABLE.
Source: 131 Linux Error Codes for C Programming Language using errno
Reference for Linux ERROR CODE TABLE.
Source: 131 Linux Error Codes for C Programming Language using errno
A Quick reference guide for C and CPP programmers for the operator precedence.
Rust for Linux? The move to make Rust a second language for developing the Linux kernel is gathering momentum. But there are still challenges ahead
Source: Rust in the Linux kernel: Why it matters and what’s happening next | ZDNet
Data structure: Way of organizing data so we can efficiently use it.
Essential ingredients in creating fast and powerful algorithms.
Help to manage and organize data.
makes code cleaner and easier to understand.
Abstract data type: Is an abstraction of a data structure which provides only the interface to which a data structure must adhere to. Interface will not give any specifics to how something should be implemented or in what programming language.
ADT – Implementation(DS)
List – Dynamic Array, Linked list.
Queue – Linked List Based queue, Array based queue, Stack base queue
Map – Tree map, Hash map, Hash table
Computational complexity analysis:
How much time does this algorithm needs to finish the computation?
How much space does this algoritm needs to finish the computation?
Big data
Omega meta data
Big-O notation: Upper bound complexity of the worst case irrespective of the size of data(small data set or large data set)
n – The size of the input
Complexities ordered in from the smallest to largest.
Constant Time : O(1)
Logarithmic Time : O(log(n))
Linear time : O(n)
Linearithmic Time : O(nlog(n))
Quadric Time : O(nsquared)
Cubic Time : O(ncube)
Exponential Time : O(bpowern), b>1
Factorial Time : O(n!)
O(n + c) = O(n)
O(cn) = O(n), c > 0
f(n) = 7 log(n)3 + 15n2 + 2n3 + 8
O(f(n)) = O(n3) as n3 is the biggest value.
An article on how to execute a command via Python.
Variables are used to store data. The following are the charateristics for the variable.
The following are the rules for a variable naming.
Data types
Storage class
Storage class defines the scope of the variable and the life time of the variable.
Source: Variables and Keywords in C – GeeksforGeeks
Example code
var.c
#include <stdio.h>
int a=1; // initialized global variable.
int b; // uninitialized global variable.
static int c; //global static variable.
extern int d;
typedef struct _abc{
char a;
short b;
int c;
}ABC;
typedef union _def{
char a;
short b;
int c;
}DEF;
int increment()
{
static int p = 5;
a=a+1;
p=p+1;
printf("dataof(p)=%d\n", p);
return 0;
}
int main(int argc, char * argv[])
{
auto int e=5; //auto variable
int f=6; //local variable
const int g=7; // constant variable
long j=10; // long type variable
long long k=11; // long long type variable
ABC h; // structure type variable
DEF i; // union type variable
char l='a'; // character type variable
short m=10; // short type variable
char *n=&l; // pointer variable.
void *o=(void *)n; // void pointer variable.
// Size check
printf("Size of char is %d bytes\n", sizeof(l));
printf("Size of short is %d bytes\n", sizeof(m));
printf("Size of int is %d bytes\n", sizeof(f));
printf("Size of long is %d bytes\n", sizeof(j));
printf("Size of long long is %d bytes\n", sizeof(k));
printf("Size of pointer is %d bytes\n", sizeof(n));
printf("Size of structure ABC is %d bytes\n", sizeof(h));
printf("Size of union DEF is %d bytes\n", sizeof(i));
//Access check
increment();
increment();
printf("dataof(a)=%d, addressof(a)=0x%x\n", a, &a);
printf("dataof(b)=%d, addressof(b)=0x%x\n", b, &b);
printf("dataof(c)=%d, addressof(c)=0x%x\n", c, &c);
printf("dataof(d)=%d, addressof(d)=0x%x\n", d, &d);
printf("dataof(e)=%d\n", e);
printf("dataof(f)=%d\n", f);
// g = g+10; in correct as its a constant
printf("dataof(g)=%d\n", g);
printf("dataof(j)=%d\n", j);
printf("dataof(k)=%d\n", k);
return 0;
}
ext.c
int d = 4;
compilation
gcc -o test var.c ext.c
Output
yogi@localhost devel]$ ./test
Size of char is 1 bytes
Size of short is 2 bytes
Size of int is 4 bytes
Size of long is 8 bytes
Size of long long is 8 bytes
Size of pointer is 8 bytes
Size of structure ABC is 8 bytes
Size of union DEF is 4 bytes
dataof(p)=6
dataof(p)=7
dataof(a)=3, addressof(a)=0x601024
dataof(b)=0, addressof(b)=0x601038
dataof(c)=0, addressof(c)=0x601034
dataof(d)=4, addressof(d)=0x60102c
dataof(e)=5
dataof(f)=6
dataof(g)=7
dataof(j)=10
dataof(k)=11
In C/C++ tokens are the smallest element of a program. Tokens can be split into the following
1. Keywords
Predefined tokens in a programming language having fixed meaning.
e.g:- switch, case, int,return etc.
C++ has 31 additional keywords
few of the common ones used are
bool, class,static_cast,try, catch etc
2. Identifiers
Identifiers are used to name variables, labels etc. There are certain rules for the identifiers
a. They can start only with a letter or underscore(_).
b. They must contain only digits, letters and underscore.
c. They cannot contain white space.
d. maximum up to 31 characters long.
e. white space not allowed.
3. Constants
Constants refer to fixed values. e.g:- integer constants, floating point constants, character constants, octal or hexadecimal constants and string constants.
E.g:-
char *p=”Yogi”;
int age=43;
In the above examples “Yogi” and 43 are string and integer constants.
4. Strings
They are array of characters ended with null character(\0)
eg:- char test[20]=”Yogi”;
5. Symbols
Symbols have special meaning.
a. Brackets[]- used for array subscripts.
b. Paranthesis() – used for function calls and parameter passing.
c. Braces{} – Used for separating blocks of code. A variable defined inside the brace will have the scope within the brace.
d. comma, – separates statements and parameters.
e. asterisk * – Use to dereference a pointer.
There are other set of symbols also used and each has its own meaning.
6. Operators
Operators are symbols that are used to perform with operands to create a statement.
Based on the number of operands operator can act upon, operators can be classified as
a. Unary operator – i++, i–;
b. Binary operators – Arithmetic, relational, logical, assignment, conditional, bitwise
c. Ternary operator – ?:
Source: C/C++ Tokens – GeeksforGeeks