answersLogoWhite

0

A variable in C Programming is a memory allocation where a value may be stored and mutated. Rather than referencing the memory allocation by its physical address, we give it an easy-to-remember name. Each variable also has a type associated with. This tells the compiler how many bytes are allocated to the variable and how those bytes are to be interpreted. That is; the same binary representation has a different meaning depending upon the type.

A pointer is also a variable. We use a pointer variable to store a memory address and thus refer to that address being pointed at. We can also dereference that address and thus indirectly access the value stored at that address. Pointers make it possible for the same algorithms to refer to different memory addresses, allowing those algorithms to operate upon the values themselves. Without pointer variables, algorithms would only be able to operate upon copies of those values.

An array is a sequence of variables of the same type arranged in contiguous memory. These variables do not have names (they are anonymous) however we can refer to them through a zero-based index. The array name provides a reference to the start of the array and the array type determines how many bytes each element occupies, thus multiplying the index by the type's length determines the offset memory address of each indexed element in the array. The only thing we cannot determine is how many elements are allocated to the array; it is up to the programmer to maintain a count of elements using a separate variable; incrementing or decrementing the count each time the array is re-allocated.

Arrays cannot be passed to or returned from functions. This is because an array implicitly converts to a pointer variable when passed to a function. In order for the function to treat this pointer as an array, we must also pass the array's length.

A constant is the same as a variable except constants are not mutable. The seemingly contradictory term "constant variable" is sometimes used, however this specifically refers to a constant that falls from scope and is subsequently re-instantiated with a new value, as will happen when a function's formal argument is declared constant or when constant memory is allocated on the heap. Formal arguments are always allocated on the call stack and will fall from scope when the function returns. Global and local constants, however, are allocated in static memory (in the program's data segment) and will remain in scope throughout the program's life cycle. All constants must be assigned a value at the point of instantiation (when they come into scope) and that value cannot be changed while the constant remains in scope.

User Avatar

Wiki User

9y ago

What else can I help you with?

Related Questions

Can static variables be declared in a header file in C programming?

Yes (but usually it is a bad idea).


How you can find greatest of three variables using c plus plus programming?

greatest = std::max (a, std::max(b, c));


What are variables in programming?

In computer programming, variables refer to a particular location in the memory that holds a value. Variables are equivalent to their assigned values.


What is token in C programming?

They're things that keep the variables in line with the void main and your functions


What is the difference between C programming and CPP programming?

C has no object oriented support. C++ is a superset of C that adds object-oriented support, but retains the concept of primitive variables. C# is a superset of C++, developed by Microsoft, that removes the concept of primitives, making it fully object-oriented but, unlike C and C++, is non-generic and is only useful for .NET programming. C# is not unlike Java, but Java is fully cross-platform and therefore has much wider support.


How do you assign the product of variables b and c to variable a?

To assign the product of variables b and c to variable a in most programming languages, you would use the assignment operator. For example, you would write a = b * c;. This statement multiplies the values of b and c, and then assigns the result to the variable a.


What type of linear programming can be found by graphical methods?

A linear programming question with two variables. Problems with three can be solved if there is a constraint that reduces them to effectively two variables. Linear programming with 3 variables, using 3-d graphs is possible but not recommended.


What is the difference between a class method and object in object-oriented C?

Class methods are the member functions that act upon member variables. An object is an instance of a class. C does not support object-oriented programming, but C++ does.


What are variables in 3 words?

Variables are placeholders for values. They can change or vary. In programming, they store data.


Can you explain the difference between pointers and variables in programming languages?

In programming languages, variables are used to store data values, while pointers are variables that store memory addresses of other variables. Variables directly hold data, while pointers hold the location of where data is stored in memory.


What is c and c in computer programming?

C and C++ are both high-level programming languages.


How are constants and variables important in devoloping java programs?

Without variables, you won't be able to do much programming. Variables is where you store data; such data may change over time. And computer programming is all about manipulating data.