Main menu

Media Coverage

<div class="small-4 columns">media 1</div>

<div class="small-4 columns">media 2</div>

<div class="small-4 columns">media 3</div>

Reach to Us

Programming Language

Difference between Big Endian and Little Endian

In big-endian format, whenever addressing memory or sending/storing words bytewise, the most significant byte — the byte containing the most significant bit — is stored first (has the lowest address) or sent first, then the following bytes are stored or sent in decreasing significance order, with the least significant byte — the one containing the least significant bit — stored last (having the highest address) or sent last. Little-endian format reverses this order: the sequence addresses/sends/stores the least significant byte first (lowest address) and the most significant byte last (highest address).
Following program o/p depends on endianess used.

main()
{
    int i =300;
    char *ptr=&i;
    *++ptr=2;
    printf("%d",i);
}

Assuming , size of int to be 4B and size of char to be 1B.
If big-endian format is followed o/p will be 131372
and else o/p will be 556.

Contributor's Info

Created:
0Comment
Sequence Points in C

Sequence points occur in the following places in C. (In C++, overloaded operators act like functions, and thus operators that have been overloaded introduce sequence points in the same way as function calls.)
 

  1. Between evaluation of the left and right operands of the && (logical AND), || (logical OR) (as part of short-circuit evaluation), and comma operators. For example, in the expression *p++ != 0 && *q++ != 0, all side effects of the sub-expression *p++ != 0 are completed before any attempt to access q.
  2. Between the evaluation of the first operand of the ternary "question-mark" operator and the second or third operand. For example, in the expression a = (*p++) ? (*p++) : 0 there is a sequence point after the first *p++, meaning it has already been incremented by the time the second instance is executed.
  3. At the end of a full expression. This category includes expression statements (such as the assignment a=b;), return statements, the controlling expressions of if, switch, while, or do-whilestatements, and all three expressions in a for statement.
  4. Before a function is entered in a function call. The order in which the arguments are evaluated is not specified, but this sequence point means that all of their side effects are complete before the function is entered. In the expression f(i++) + g(j++) + h(k++), f is called with a parameter of the original value of i, but i is incremented before entering the body of f. Similarly, j and k are updated before entering g and h respectively. However, it is not specified in which order f(), g(), h() are executed, nor in which order i, j, k are incremented. If the body of f accesses the variables j and k, it might find both, neither, or just one of them to have been incremented. (The function call f(a,b,c) is not a use of the comma operator; the order of evaluation for a, b, and c is unspecified.)
  5. At a function return, after the return value is copied into the calling context. (This sequence point is only specified in the C++ standard; it is present only implicitly in C.
  6. At the end of an initializer; for example, after the evaluation of 5 in the declaration int a = 5;.
  7. Between each declarator in each declarator sequence; for example, between the two evaluations of a++ in int x = a++, y = a++.(This is not an example of the comma operator.)
  8. After each conversion associated with an input/output format specifier. For example, in the expression printf("foo %n %d", &a, 42), there is a sequence point after the %n is evaluated and before printing 42.

Several examples of Sequence Point in C are:

  • i++ && i++
  • i++ * i++
  • a[i] = i++
  • printf("%d %d %d", i, ++i, i++)
  • All these sequence points in C results in undefined behaviour where output is compiler dependent.

Contributor's Info

Created:
0Comment
Programming Language

This course aims to cover aspects of Programming Language giving emphasis to C language.

The chapters we will cover are as following:
1. Introduction
2. Functions
3. Pointers
4. Storage Classes
5. Scoping and Binding

Contributor's Info

Created:
0Comment