register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the size of a processor's general-purpose registers (GPRs) and the default size is usually one word or 2 byte or 16 bits.
This blog provides some ready-made tips, tricks, tweaks & interview questions-answers on C, C++, Perl, Shell Scripting and UNIX Commands.
Wednesday, February 27, 2013
What are Bit-fields?
The variables defined with a fixed width are called bit fields. A well-known usage of bit-fields is to represent a set of bits, and/or series of bits. They are space-saving structure members. They allow integer members to be stored into memory spaces smaller than the compiler would ordinarily allow. The default integer type for a bit field is unsigned.
The declaration of a bit-field inside a structure has the form:
struct
{
type [member_name] : width ;
};
The declaration of a bit-field inside a structure has the form:
struct
{
type [member_name] : width ;
};
What is a self-referential structure?
A structure containing a reference to itself as a member is known as Self-Referential Structure.
struct linked_list_node
{
int data;
struct linked_list_node *next; // self reference
};
struct linked_list_node
{
int data;
struct linked_list_node *next; // self reference
};
What do you mean by associativity and precedence?
Precedence denotes the order or priority of evaluation whereas associativity implies the direction of evaluation.
What are dangling, wild, void, and null pointers?
A pointer pointing to a memory location which is deleted or freed is known as Dangling Pointer.
A pointer which has not necessarily initialized prior to its usage is a Wild Pointer.
A pointer pointing to nothing or that does not refer to a valid memory location is a NULL Pointer.
The pointer not having any type associated with it and can hold the address of any type is known as Void Pointer (aka Generic Pointer).
Are functions declared or defined in header files?
Traditionally the standard functions are declared in header files and defined in the library routines only.
What is the difference between '#include' and '#include "File"'?
It is compiler dependent. Generallly '#include "File"' prioritizes headers to be checked in the current working directory over system headers. And if there is not a suitable match, it moves on to check the system paths. "#include <File>" always looks out for system headers.
How could you find the size of a variable with out using sizeof operator?
#include <stdio.h>
#define SIZEOF(var) ((size_t)(&(var)+1) - (size_t)(&(var)))
main( )
{
int x;
printf ("The size of x is %d\n", SIZEOF(x) );
}
Monday, February 25, 2013
How could you multiply 2 Integers using bit-wise operators?
#include<stdio.h>
main()
{
int a, b, num1, num2, result=0;
printf("\nEnter the numbers to be multiplied :");
scanf("%d%d",&num1,&num2);
a=num1;
b=num2;
while(num2 != 0)
{
if (num2 & 01)
{
result+=num1;
}
num1<<=1;
num2>>=1;
}
printf("\nMultiplication of %d*%d=%d", a, b, result);
}
What is the difference between '#define' and 'typedef'?
(a) typedef keep the property of attributes whereas #define doesn’t. For example
typedef char *type_t;
#define char *type_d
type_t s1,s2;
type_d s3,s4;
In the above declarations, s1,s2 and s3 are all declared as char* but s4 is declared as a char, which is probably not the intention.
(b) #define keeps string attributes whereas typedef doesn’t.
#define int INT;
typedef int MYINT
unsigned MYINT a;
unsigned INT a; /* Illegal */
For the typedef scenario, it doesn't change to unsigned 'int a' but in #define case it works!!!.
Subscribe to:
Posts
(
Atom
)