0 like 0 dislike
51 views
in Computer Science by (1.0m points)
What is meant by initializing a variable in C.

1 Answer

0 like 0 dislike
by (1.0m points)
In computer programming, initialization is the assignment of an initial value for a data object or variable. The manner in which initialization is performed depends on programming language, as well as type, storage class, etc., of an object to be initialized. Programming constructs which perform initialization are typically called initializers and initializer lists. Initialization is distinct from (and preceded by) declaration, although the two can sometimes be conflated in practice. The complement of initialization is finalization, which is primarily used for objects, but not variables.

Initialization is done either by statically embedding the value at compile time, or else by assignment at run time. A section of code that performs such initialization is generally known as "initialization code" and may include other, one-time-only, functions such as opening files; in object-oriented programming, initialization code may be part of a constructor (class method) or an initializer (instance method). Setting a memory location to hexadecimal zeroes is also sometimes known as "clearing" and is often performed by an exclusive or instruction (both operands specifying the same variable), at machine code level, since it requires no additional memory access.

C family of languages

Initializer

In C/C99/C++, an initializer is an optional part of a declarator. It consists of the '=' character followed by an expression or a comma-separated list of expressions placed in curly brackets (braces). The latter list is sometimes called the "initializer list" or "initialization list" (although the term "initializer list" is formally reserved for initialization of class/struct members in C++; see below). A declaration which includes initialization is commonly called definition.

Many find it convenient to draw a distinction between the terms "declaration" and "definition", as in the commonly seen phrase "the distinction between a declaration and definition...", implying that a declaration merely designates a data object (or function). In fact, according to the C++ standard, a definition is a declaration. Still, the usage "declarations and definitions", although formally incorrect, is common.[1]

Related questions

0 like 0 dislike
1 answer 34 views
0 like 0 dislike
1 answer 55 views
0 like 0 dislike
1 answer 60 views
asked Feb 13, 2019 in Computer Science by danish (1.0m points)
0 like 0 dislike
1 answer 37 views
asked Feb 11, 2019 in Computer Science by danish (1.0m points)
0 like 0 dislike
1 answer 49 views
0 like 0 dislike
1 answer 505 views
0 like 0 dislike
1 answer 89 views
0 like 0 dislike
0 answers 82 views
0 like 0 dislike
1 answer 93 views
Welcome to Free Homework Help, where you can ask questions and receive answers from other members of the community. Anybody can ask a question. Anybody can answer. The best answers are voted up and rise to the top. Join them; it only takes a minute: School, College, University, Academy Free Homework Help

19.4k questions

18.3k answers

8.7k comments

6.3k users

Free Hit Counters
...