In computer science, a union is a value that may have any of several representations or formats within the same position in memory; that consists of a variable that may hold such a data structure. Some programming languages support special data types, called union types, to describe such values and variables.

In other words, a union type definition will specify which of a number of permitted primitive types may be stored in its instances, e.g., "float or long integer". In contrast with a record (or structure), which could be defined to contain a float and an integer; in a union, there is only one value at any given time.

Initialization

Because of the language's grammar, a scalar initializer may be enclosed in any number of curly brace pairs. Most compilers issue a warning if there is more than one such pair, though.

int x = 12;
int y = { 23 };     //Legal, no warning
int z = { { 34 } }; //Legal, expect a warning

Declaration

The general syntax for a struct declaration in C is:

struct tag_name {
   type member1;
   type member2;
   /* declare as many members as desired, but the entire structure size must be known to the compiler. */
};

Dynamic arrays

Arrays that can be resized dynamically can be produced with the help of the C standard library. The malloc function provides a simple method for allocating memory. It takes one parameter: the amount of memory to allocate in bytes. Upon successful allocation, malloc returns a generic (void) pointer value, pointing to the beginning of the allocated space. The pointer value returned is converted to an appropriate type implicitly by assignment. If the allocation could not be completed, malloc returns a null pointer. The following segment is therefore similar in function to the above desired declaration:

NO gets() in C11 standard !!!  NO gets() in C11 standard !!!  NO gets() in C11 standard !!!   

string input/output in C

#inlude <stdio.h>

    • scanf("%s", str);
    • printf("%s", str);
    • gets(str);
    • puts(str);
    • getchar();
    • putchar();

  • gets(), a computer programming function that reads a line of input 

BUT, NEVER EVER use gets() !!!

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. 
A string is generally understood as a data type and is often implemented as an array of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding
A string may also denote more general arrays or other sequence (or list) data types and structures.

In computer science, a pointer is a programming language object, whose value refers to (or "points to") another value stored elsewhere in the computer memory using its memory address.

A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer.

As an analogy, a page number in a book's index could be considered a pointer to the corresponding page; dereferencing such a pointer would be done by flipping to the page with the given page number.

In the Cconst is a type qualifier,  a keyword applied to a data type that indicates that the data is read only. 

简单的例子:

  • char const foo = 'a';

变量foo不允许被修改,

  • void Foo(int const a[]);

数组a在函数Foo中禁止被修改。

 

实际使用中设计指针时比较复杂。

https://en.wikipedia.org/wiki/Const_(computer_programming)

Variables

Variables in programming languages are abstraction of memory cells.

Variable has three attributes:

  • name,
  • type,
  • value.

One more attribute is its location in memory:

  • address.

Array as a whole can be used as function parameter.

for example: here we design a function to do mergesort. The prototype is as follows,