- Home
- Interview Questions
- C Programming
Pointers give you more control over the computer and your data. When used with functions, pointers let you change the values of variables that were passed, regardless of where they originated.
The compiler interprets the different uses of the asterisk based on the context in which it is used. If the statement being evaluated starts with a variable type, it can be assumed that the asterisk is for declaring a pointer. If the asterisk is used with a variable that has been declared as a pointer, but not in a variable declaration, the asterisk is assumed to dereference. If it is used in a mathematical expression, but not with a pointer variable, the asterisk can be assumed to be the multiplication operator.
You get the address of the pointer variable. Remember, a pointer is just another variable that holds the address of the variable to which it points.
No. Each time a program runs, its variables can be stored at different addresses within the computer. You should never assign a constant address value to a pointer.
Although it might seem easier to declare large arrays, this isn't an effective use of memory. When you’re writing small programs, such as those in today's lesson, it might seem trivial to use a function such as malloc() instead of arrays, but as your programs get bigger, you'll want to be able to allocate memory only as needed. When you're done with memory, you can put it back by freeing it. When you free memory, some other variable or array in a different part of the program can use it.
No. Most PCs support the extended ASCII set. Some older PCs don’t, but the number
of older PCs lacking this support is diminishing. Most programmers use the
line and block characters of the extended set.
Additionally, many international character sets contain more than characters available
in ASCII. These characters are usually stored in wchar_t type variables
instead of variables of type char. wchar_t is defined in the stddef.h header file. It
can be used to hold larger characters. Check the ANSI documents for more information
on using wchar_t and other character sets.
This can cause a hard-to-find error. You can do this in C, but anything stored in the memory directly after the character array is overwritten. This could be an area of memory not used, some other data, or some vital system information. Your results will depend on what you overwrite. Often, nothing happens for a while. You don’t want to do this.
You can see two ways of declaring a structure. The first is to declare a structure body, tag, and instance all at once. The second is to declare a structure body and tag without an instance. An instance can then be declared later by using the struct keyword, the tag, and a name for the instance. It’s common programming practice to use the second method. Many programmers declare the structure body and tag without any instances. The instances are then declared later in the program. Tomorrow’s lesson describes variable scope. Scope will apply to the instance, but not to the tag or structure body.
Many programmers use typedefs to make their code easier to read, but it makes little practical difference. Many add-in libraries that contain functions are available for purchase. These add-ins usually have a many typedefs to make the product unique. This is especially true of database add-in products.
Yes and no. Newer versions of C compilers let you assign one structure to another, but older versions might not. In older versions of C, you might need to assign each member of the structures individually. This is true of unions, also.