Your Ad Here
0

What is the difference between class and structure?

Posted by The Blogger on 8:25 AM in
Answer:

Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all the members inside the class are private.


interview questions and answers, interview question What is the difference between class and structure, What is the difference between class and structure

0

Define a constructor - What it is and how it might be called?

Posted by The Blogger on 8:24 AM in
Answer1
constructor is a member function of the class, with the name of the function being the same as the class name. It also specifies how the object should be initialized.

Ways of calling constructor:
1) Implicitly: automatically by complier when an object is created.
2) Calling the constructors explicitly is possible, but it makes the code unverifiable.

Answer2
class Point2D{
int x; int y;
public Point2D() : x(0) , y(0) {} //default (no argument) constructor
};

main(){

Point2D MyPoint; // Implicit Constructor call. In order to allocate memory on stack, the default constructor is implicitly called.

Point2D * pPoint = new Point2D(); // Explicit Constructor call. In order to allocate memory on HEAP we call the default constructor.



interview questions and answers, interview question Define a constructor - What it is and how it might be called, Define a constructor - What it is and how it might be called

0

What are the advantages of inheritance?

Posted by The Blogger on 8:23 AM in
Answer:

• It permits code reusability.
• Reusability saves time in program development.
• It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.


interview questions and answers, interview question What are the advantages of inheritance, What are the advantages of inheritance

0

What is virtual constructors/destructors?

Posted by The Blogger on 8:22 AM in
Answer1

Virtual destructors:
If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object.
There is a simple solution to this problem declare a virtual base-class destructor.
This makes all derived-class destructors virtual even though they don’t have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called. Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error.


Answer2

Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object.
There is a simple solution to this problem – declare a virtual base-class destructor. This makes all derived-class destructors virtual even though they don’t have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called.



interview questions and answers, interview question What is virtual constructors/destructors, What is virtual constructors/destructors, constructors, destructor

0

What is public, protected, private?

Posted by The Blogger on 8:20 AM in
Answer:

Public, protected and private are three access specifier in C++.
Public data members and member functions are accessible outside the class.
Protected data members and member functions are only available to derived classes.
Private data members and member functions can’t be accessed outside the class. However there is an exception can be using friend classes.
Write a function that swaps the values of two integers, using int* as the argument type.
void swap(int* a, int*b) {
int t;
t = *a;
*a = *b;
*b = t;
}


interview questions and answers, interview question What is public, protected, private, What is public, protected, private, public private protected cpp

0

What do you mean by inline function?

Posted by The Blogger on 8:19 AM in
Answer:

The idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated binary executables.


interview questions and answers, interview question What do you mean by inline function, What do you mean by inline function

0

How do you write a function that can reverse a linked-list?

Posted by The Blogger on 8:18 AM in
Answer:

void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur-> next = head;

for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}

curnext->next = cur;
}
}



interview questions and answers, interview question How do you write a function that can reverse a linked-list, How do you write a function that can reverse a linked-list, reverse a linked list, linked list

0

What is the difference between declaration and definition?

Posted by The Blogger on 8:17 AM in
Answer:

The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
E.g.: void stars () //function declaration
The definition contains the actual implementation.
E.g.: void stars () // declarator
{
for(int j=10; j > =0; j--) //function body
cout << *;
cout << endl; }


interview questions and answers, interview What is the difference between declaration and definition, What is the difference between declaration and definition, declaration and definition

0

What is function overloading and operator overloading?

Posted by The Blogger on 8:16 AM in
Answer:

Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.
Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).


tags: interview questions and answers, interview question What is function overloading and operator overloading, What is function overloading and operator overloading

0

What is the difference between realloc() and free()?

Posted by The Blogger on 8:15 AM in
Answer:

The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

tags:interview questions and answers, interview questions What is the difference between realloc() and free(), What is the difference between realloc() and free()

0

What is C++?

Posted by The Blogger on 8:08 AM in
Released in 1985, C++ is an object-oriented programming language created by Bjarne Stroustrup. C++ maintains almost all aspects of the C language, while simplifying memory management and adding several features - including a new datatype known as a class (you will learn more about these later) - to allow object-oriented programming. C++ maintains the features of C which allowed for low-level memory access but also gives the programmer new tools to simplify memory management.

C++ used for:

C++ is a powerful general-purpose programming language. It can be used to create small programs or large applications. It can be used to make CGI scripts or console-only DOS programs. C++ allows you to create programs to do almost anything you need to do. The creator of C++, Bjarne Stroustrup, has put together a partial list of applications written in C++.


interview questions and answers, interview question what is C++ cpp cpluspluss, what is c++ cpp cplusplus

0

When does the compiler not implicitly generate the address of the first element of an array ?

Posted by The Blogger on 9:35 AM in
Answer:

Whenever an array name appears in an expression such as

* array as an operand of the sizeof operator
* array as an operand of & operator
* array as a string literal initializer for a character array

Then the compiler does not implicitly generate the address of the address of the first element of an array.


tags: c interview questions and answers, c interview question When does the compiler not implicitly generate the address of the first element of an array, When does the compiler not implicitly generate the address of the first element of an array

0

What is page thrashing ?

Posted by The Blogger on 9:33 AM in ,
Answer:

Some operating systems (such as UNIX or Windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk space to simulate RAM (random-access memory).

In the 80386 and higher Intel CPU chips, and in most other modern microprocessors (such as the Motorola 68030, Sparc, and Power PC), exists a piece of hardware called the Memory Management Unit, or MMU.

The MMU treats memory as if it were composed of a series of pages. A page of memory is a block of contiguous bytes of a certain size, usually 4096 or 8192 bytes. The operating system sets up and maintains a table for each running program called the Process Memory Map, or PMM. This is a table of all the pages of memory that program can access and where each is really located.

Every time your program accesses any portion of memory, the address (called a virtual address) is processed by the MMU. The MMU looks in the PMM to find out where the memory is really located (called the physical address). The physical address can be any location in memory or on disk that the operating system has assigned for it. If the location the program wants to access is on disk, the page containing it must be read from disk into memory, and the PMM must be updated to reflect this action (this is called a page fault).

Because accessing the disk is so much slower than accessing RAM, the operating system tries to keep as much of the virtual memory as possible in RAM. If you’re running a large enough program (or several small programs at once), there might not be enough RAM to hold all the memory used by the programs, so some of it must be moved out of RAM and onto disk (this action is called paging out).

The operating system tries to guess which areas of memory aren’t likely to be used for a while (usually based on how the memory has been used in the past). If it guesses wrong, or if your programs are accessing lots of memory in lots of places, many page faults will occur in order to read in the pages that were paged out. Because all of RAM is being used, for each page read in to be accessed, another page must be paged out. This can lead to more page faults, because now a different page of memory has been moved to disk.

The problem of many page faults occurring in a short time, called page thrashing, can drastically cut the performance of a system. Programs that frequently access many widely separated locations in memory are more likely to cause page thrashing on a system. So is running many small programs that all continue to run even when you are not actively using them.

To reduce page thrashing, you can run fewer programs simultaneously. Or you can try changing the way a large program works to maximize the capability of the operating system to guess which pages won’t be needed. You can achieve this effect by caching values or changing lookup algorithms in large data structures, or sometimes by changing to a memory allocation library which provides an implementation of malloc() that allocates memory more efficiently. Finally, you might consider adding more RAM to the system to reduce the need to page out.

tags: c interview questions and answers, c interview question What is page thrashing, What is page thrashing, page thrashing

0

How can you determine the size of an allocated portion of memory ?

Posted by The Blogger on 9:32 AM in
Answer:

You can’t, really. free() can , but there’s no way for your program to know the trick free() uses. Even if you disassemble the library and discover the trick, there’s no guarantee the trick won’t change with the next release of the compiler.


tags: c interview questions and answers, c interview question How can you determine the size of an allocated portion of memory, How can you determine the size of an allocated portion of memory

0

When should the register modifier be used?

Posted by The Blogger on 9:30 AM in
Answer:

The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster.
There are several restrictions on the use of the register modifier.

First, the variable must be of a type that can be held in the CPU’s register. This usually means a single value of a size less than or equal to the size of an integer. Some machines have registers that can hold floating-point numbers as well.

Second, because the variable might not be stored in memory, its address cannot be taken with the unary & operator. An attempt to do so is flagged as an error by the compiler. Some additional rules affect how useful the register modifier is. Because the number of registers is limited, and because some registers can hold only certain types of data (such as pointers or floating-point numbers), the number and types of register modifiers that will actually have any effect are dependent on what machine the program will run on. Any additional register modifiers are silently ignored by the compiler.

Also, in some cases, it might actually be slower to keep a variable in a register because that register then becomes unavailable for other purposes or because the variable isn’t used enough to justify the overhead of loading and storing it.

So when should the register modifier be used? The answer is never, with most modern compilers. Early C compilers did not keep any variables in registers unless directed to do so, and the register modifier was a valuable addition to the language.

C compiler design has advanced to the point, however, where the compiler will usually make better decisions than the programmer about which variables should be stored in registers.

In fact, many compilers actually ignore the register modifier, which is perfectly legal, because it is only a hint and not a directive.

tags: c interview questions and answers, c interview question When should the register modifier be used, When should the register modifier be used

0

When should the volatile modifier be used ?

Posted by The Blogger on 9:26 AM in
Answer:

The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the volatile modifier is desirable. The first case involves memory-mapped hardware (a device such as a graphics adaptor that appears to the computer’s hardware as if it were part of the computer’s memory), and the second involves shared memory (memory used by two or more programs running simultaneously).

Most computers have a set of registers that can be accessed faster than the computer’s main memory. A good compiler will perform a kind of optimization called redundant load and store removal. The compiler looks for places in the code where it can either remove an instruction to load data from memory because the value is already in a register, or remove an instruction to store data to memory because the value can stay in a register until it is changed again anyway.
If a variable is a pointer to something other than normal memory, such as memory-mapped ports on a peripheral, redundant load and store optimizations might be detrimental. For instance, here’s a piece of code that might be used to time some operation:

time_t time_addition(volatile const struct timer *t, int a)
{
int n;
int x;
time_t then;
x = 0;
then = t->value;
for (n = 0; n < 1000; n++)
{
x = x + a;
}
return t->value - then;
}

In this code, the variable t-> value is actually a hardware counter that is being incremented as time passes. The function adds the value of a to x 1000 times, and it returns the amount the timer was incremented by while the 1000 additions were being performed. Without the volatile modifier, a clever optimizer might assume that the value of t does not change during the execution of the function, because there is no statement that explicitly changes it. In that case, there’s no need to read it from memory a second time and subtract it, because the answer will always be 0.

The compiler might therefore optimize the function by making it always return 0.
If a variable points to data in shared memory, you also don’t want the compiler to perform redundant load and store optimizations. Shared memory is normally used to enable two programs to communicate with each other by having one program store data in the shared portion of memory and the other program read the same portion of memory. If the compiler optimizes away a load or store of shared memory, communication between the two programs will be affected.


tags: c interview questions and answers, c interview question When should the volatile modifier be used, When should the volatile modifier be used

0

What is the benefit of using an enum rather than a #define constant ?

Posted by The Blogger on 9:24 AM in
Answer:

The use of an enumeration constant (enum) has many advantages over using the traditional symbolic constant style of #define. These advantages include a lower maintenance requirement, improved program readability, and better debugging capability.
1) The first advantage is that enumerated constants are generated automatically by the compiler. Conversely, symbolic constants must be manually assigned values by the programmer.
For instance, if you had an enumerated constant type for error codes that could occur in your program, your enum definition could look something like this:
enum Error_Code
{
OUT_OF_MEMORY,
INSUFFICIENT_DISK_SPACE,
LOGIC_ERROR,
FILE_NOT_FOUND
};
In the preceding example, OUT_OF_MEMORY is automatically assigned the value of 0 (zero) by the compiler because it appears first in the definition. The compiler then continues to automatically assign numbers to the enumerated constants, making INSUFFICIENT_DISK_SPACE equal to 1, LOGIC_ERROR equal to 2, and FILE_NOT_FOUND equal to 3, so on.
If you were to approach the same example by using symbolic constants, your code would look something like this:
#define OUT_OF_MEMORY 0
#define INSUFFICIENT_DISK_SPACE 1
#define LOGIC_ERROR 2
#define FILE_NOT_FOUND 3
values by the programmer. Each of the two methods arrives at the same result: four constants assigned numeric values to represent error codes. Consider the maintenance required, however, if you were to add two constants to represent the error codes DRIVE_NOT_READY and CORRUPT_FILE. Using the enumeration constant method, you simply would put these two constants anywhere in the enum definition. The compiler would generate two unique values for these constants. Using the symbolic constant method, you would have to manually assign two new numbers to these constants. Additionally, you would want to ensure that the numbers you assign to these constants are unique.
2) Another advantage of using the enumeration constant method is that your programs are more readable and thus can be understood better by others who might have to update your program later.

3) A third advantage to using enumeration constants is that some symbolic debuggers can print the value of an enumeration constant. Conversely, most symbolic debuggers cannot print the value of a symbolic constant. This can be an enormous help in debugging your program, because if your program is stopped at a line that uses an enum, you can simply inspect that constant and instantly know its value. On the other hand, because most debuggers cannot print #define values, you would most likely have to search for that value by manually looking it up in a header file.


tags: c interview questions and answers, c interview question What is the benefit of using an enum rather than a #define constant, What is the benefit of using an enum rather than a #define constant

0

Difference between const char* p and char const* p ?

Posted by The Blogger on 9:22 AM in
Answer:

In const char* p, the character pointed by ‘p’ is constant, so u can't change the value of character pointed by p but u can make ‘p’ refer to some other location.

in char const* p, the ptr ‘p’ is constant not the character referenced by it, so u can't make ‘p’ to reference to any other location but u can change the value of the char pointed by ‘p’.



tags: c interview questions and answers, c interview question Difference between const char* p and char const* p, Difference between const char* p and char const* p

0

Why does malloc(0) return valid memory address ? What's the use ?

Posted by The Blogger on 9:20 AM in
Answer:

malloc(0) does not return a non-NULL under every implementation.
An implementation is free to behave in a manner it finds
suitable, if the allocation size requested is zero. The
implmentation may choose any of the following actions:

* A null pointer is returned.

* The behavior is same as if a space of non-zero size
was requested. In this case, the usage of return
value yields to undefined-behavior.

Notice, however, that if the implementation returns a non-NULL
value for a request of a zero-length space, a pointer to object
of ZERO length is returned! Think, how an object of zero size
should be represented?

For implementations that return non-NULL values, a typical usage
is as follows:

void
func ( void )
{
int *p; /* p is a one-dimensional array,
whose size will vary during the
the lifetime of the program */
size_t c;

p = malloc(0); /* initial allocation */
if (!p)
{
perror (”FAILURE” );
return;
}

/* … */

while (1)
{
c = (size_t) … ; /* Calculate allocation size */
p = realloc ( p, c * sizeof *p );

/* use p, or break from the loop */
/* … */
}
return;
}

Notice that this program is not portable, since an implementation
is free to return NULL for a malloc(0) request, as the C Standard
does not support zero-sized objects.


tags: c interview questions and answers, c interview question Why does malloc(0) return valid memory address, Why does malloc(0) return valid memory address

0

Which bit wise operator is suitable for putting on a particular bit in a number ?

Posted by The Blogger on 9:19 AM in ,
Answer:

The bitwise OR operator. In the following code snippet, the bit number 24 is turned ON:

some_int = some_int | KBit24;


tags: c interview questions and answers, c interview question Which bit wise operator is suitable for putting on a particular bit in a number, Which bit wise operator is suitable for putting on a particular bit in a number

0

Which bit wise operator is suitable for turning off a particular bit in a number?

Posted by The Blogger on 9:18 AM in
Answer:

The bitwise AND operator, again. In the following code snippet, the bit number 24 is reset to zero.

some_int = some_int & ~KBit24;

tags: c interview questions and answers, c interview question Which bit wise operator is suitable for turning off a particular bit in a number, Which bit wise operator is suitable for turning off a particular bit in a number

0

Which bit wise operator is suitable for checking whether a particular bit is on or off ?

Posted by The Blogger on 9:16 AM in
Answer:

The bitwise AND operator. Here is an example:

enum {
KBit0 = 1,
KBit1,

KBit31,
};

if ( some_int & KBit24 )
printf ( “Bit number 24 is ON\n” );
else
printf ( “Bit number 24 is OFF\n” );


tags: c interview questions and answers, c interview question Which bit wise operator is suitable for checking whether a particular bit is on or off, Which bit wise operator is suitable for checking whether a particular bit is on or off,bitwise operators

0

Write down the equivalent pointer expression for referring the same element a[i][j][k][l] ?

Posted by The Blogger on 9:11 AM in
Answer:

a[i] == *(a+i)
a[i][j] == *(*(a+i)+j)
a[i][j][k] == *(*(*(a+i)+j)+k)
a[i][j][k][l] == *(*(*(*(a+i)+j)+k)+l)


tags: c interview questions and answers, c interview question Write down the equivalent pointer expression for referring the same element a[i][j][k][l], Write down the equivalent pointer expression for referring the same element a[i][j][k][l]

0

What is the difference between strings and character arrays ?

Posted by The Blogger on 9:09 AM in
Answer:

A major difference is: string will have static storage duration, whereas as a character array will not, unless it is explicity specified by using the static keyword.

Actually, a string is a character array with following properties:

* the multibyte character sequence, to which we generally call string, is used to initialize an array of static storage duration. The size of this array is just sufficient to contain these characters plus the terminating NUL character.

* it not specified what happens if this array, i.e., string, is modified.

* Two strings of same value[1] may share same memory area. For example, in the following declarations:

char *s1 = “Calvin and Hobbes”;
char *s2 = “Calvin and Hobbes”;

the strings pointed by s1 and s2 may reside in the same memory location. But, it is not true for the following:

char ca1[] = “Calvin and Hobbes”;
char ca2[] = “Calvin and Hobbes”;

[1] The value of a string is the sequence of the values of the contained characters, in order.



tags: c interview questions and answers, c interview question What is the difference between strings and character arrays, What is the difference between strings and character arrays, strings, character arrays

0

What are the advantanges of macro over a function ?

Posted by The Blogger on 9:08 AM in
Answer:

Macro gets to see the Compilation environment, so it can expand __ __TIME__ __FILE__ #defines. It is expanded by the preprocessor.

For example, you can’t do this without macros
#define PRINT(EXPR) printf( #EXPR “=%d\n”, EXPR)

PRINT( 5+6*7 ) // expands into printf(”5+6*7=%d”, 5+6*7 );

You can define your mini language with macros:
#define strequal(A,B) (!strcmp(A,B))

Macros are a necessary evils of life. The purists don’t like them, but without it no real work gets done.


tags: c interview questions and answers, c interview question What are the advantanges of macro over a function, What are the advantanges of macro over a function, advantages of macro, macro, function

0

What is the difference between printf() and sprintf() ?

Posted by The Blogger on 9:06 AM in
Answer:

sprintf() writes data to the character array whereas printf(...) writes data to the standard output device.


tags: c interview questions and answers, c interview question What is the difference between printf() and sprintf(), What is the difference between printf() and sprintf(), printf, sprintf

0

What is the difference between calloc() and malloc() ?

Posted by The Blogger on 9:05 AM in ,
Answer:

1. calloc(...) allocates a block of memory for an array of elements of a certain size. By default the block is initialized to 0. The total number of memory allocated will be (number_of_elements * size).

malloc(...) takes in only a single argument which is the memory required in bytes. malloc(...) allocated bytes of memory and not blocks of memory like calloc(...).

2. malloc(...) allocates memory blocks and returns a void pointer to the allocated space, or NULL if there is insufficient memory available.

calloc(...) allocates an array in memory with elements initialized to 0 and returns a pointer to the allocated space. calloc(...) calls malloc(...) in order to use the C++ _set_new_mode function to set the new handler mode.


tags: c interview questions and answers, c interview question What is the difference between calloc() and malloc(), What is the difference between calloc() and malloc(), calloc, malloc

0

What is the output of printf("%d") ?

Posted by The Blogger on 9:03 AM in ,
Answer:

1. When we write printf("%d",x); this means compiler will print the value of x. But as here, there is nothing after %d so compiler will show in output window garbage value.

2. When we use %d the compiler internally uses it to access the argument in the stack (argument stack). Ideally compiler determines the offset of the data variable depending on the format specification string. Now when we write printf("%d",a) then compiler first accesses the top most element in the argument stack of the printf which is %d and depending on the format string it calculated to offset to the actual data variable in the memory which is to be printed. Now when only %d will be present in the printf then compiler will calculate the correct offset (which will be the offset to access the integer variable) but as the actual data object is to be printed is not present at that memory location so it will print what ever will be the contents of that memory location.

3. Some compilers check the format string and will generate an error without the proper number and type of arguments for things like printf(...) and scanf(...).
malloc()


tags: c interview questions and answers, c interview question What is the output of printf("%d") , What is the output of printf("%d") , printf

0

What is a null pointer?

Posted by The Blogger on 9:01 AM in ,
Answer:

There are times when it’s necessary to have a pointer that doesn’t point to anything. The macro NULL, defined in , has a value that’s guaranteed to be different from any valid pointer. NULL is a literal zero, possibly cast to void* or char*.

Some people, notably C++ programmers, prefer to use 0 rather than NULL.

The null pointer is used in three ways:

1) To stop indirection in a recursive data structure.
2) As an error value.
3) As a sentinel value.

tags: c interview questions and answers, c interview question What is a null pointer, What is a null pointer, null pointer, null, pointer

0

Can static variables be declared in a header file ?

Posted by The Blogger on 8:59 AM in
Answer:

You can’t declare a static variable without defining it as well (this is because the storage class modifiers static and extern are mutually exclusive). A static variable can be defined in a header file, but this would cause each source file that included the header file to have its own private copy of the variable, which is probably not what was intended.

tags: c interview questions and answers, c interview question Can static variables be declared in a header file, Can static variables be declared in a header file, static variables, header file

0

What are the different storage classes in C ?

Posted by The Blogger on 8:56 AM in
Answer:

C has three types of storage: automatic, static and allocated.

Variable having block scope and without static specifier have automatic storage duration.

Variables with block scope, and with static specifier have static scope. Global variables (i.e, file scope) with or without the the static specifier also have static scope.

Memory obtained from calls to malloc(), alloc() or realloc() belongs to allocated storage class.

tags: c interview questions and answers, c interview question What are the different storage classes in C, What are the different storage classes in C, storage classes, storage

0

What does static variable mean?

Posted by The Blogger on 8:53 AM in ,
Answer:

There are 3 main uses for the static.

1. If you declare within a function:
It retains the value between function calls

2.If it is declared for a function name:
By default function is extern..so it will be visible from other files if the function declaration is as static..it is invisible for the outer files

3. Static for global variables:
By default we can use the global variables from outside files If it is static global..that variable is limited to with in the file.

tags: c interview questions and answers, c interview question What does static variable mean, What does static variable mean, static variable, static

Your Ad Here

Copyright © 2009 Interview Questions and Answers