auto inc

download auto inc

If you can't read please download the document

description

dfsdfsdf

Transcript of auto inc

What are the different properties of variable number of arguments?The properties of variable number of arguments are as follows:The first parameter of the argument should be of any data type. The invalidDeclaration of a function will be done likeint(a);The valid declaration of the function will be like:int(char c);void(int,float);There should not be any passing from one data type to another data type. There is also invalid declaration on the basis of:int(int a,int b);There should not be any blank spaces in between the two periods. The placing of any other data type can be done in place of ellipsis.How does normalization of huge pointer works?Huge pointer is the pointer that can point to the whole memory of the RAM and that can access all the segments that are present in a program. The normalization can be done depending on the microprocessor of the system. The physical memory of the system is represented in 20 bit and then there is a conversion of 4 byte or 32 bit address. The increment of the huge pointer will also affect the offset and segment address. Through the huge pointer the access and modification of device driver memory, video memory, etc. Huge pointer manages the overall system of the memory model and also normalizes the overall use of the pointers.What are the different types of pointers used in C language?There are three types of pointers used in C language. These pointers are based on the old system architecture. The types are as follows:a) Near pointer: this is the pointer that points only to the data segment. There is a restriction of using it beyond the data segment. The near pointer can be made by using the keyword as near.b) Far pointer: it will access the total memory of the system and can be use to point to every object used in the memory.c) Wild pointer: it is a pointer that is not being initialized.What is the difference between null pointer and wild pointer?Wild pointer is used to point to the object but it is not in initialization phase. Null pointer points to the base address of a particular segment. Wild pointer consists of the addresses that are out of scope whereas null pointer consists of the addresses that are accessible and in the scope. Wild pointer is declared and used in local scope of the segment whereas null is used in the full scope.What is the function of dangling pointer?Dangling pointer is used as a wild pointer only that is pointing to the memory address of the variable that is been deleted from memory location. Dangling pointer points to a memory location still even the pointer is being removed from the segment. When an object is deleted or deallocated then the problem of dangling pointer arises. In this condition if the user tries to reallocate the freed memory to another process then the original program gives different behavior from the one it is expected from the program.Wild pointer questions and explanation in c languageA pointer in c which has not been initialized is known as wild pointer. For Example:What will be output of following c program? #includeint main(){int *ptr;printf("%u\n",ptr);printf("%d",*ptr); return 0;}Output: Any addressGarbage valueHere ptr is wild pointer because it has not been initialized.There is difference between the NULL pointer and wild pointer. Null pointer points the base address of segment while wild pointer doesnt point any specific memory location.Generic pointer in c programmingGeneric pointer:void pointer in c is known as generic pointer. Literal meaning of generic pointer is a pointer which can point type of data.Example:void *ptr;Here ptr is generic pointer.Important points about generic pointer in c?1. We cannot dereference generic pointer.#include#include int main(){void *ptr;printf("%d",*ptr);return 0;}Output: Compiler error2. We can find the size of generic pointer using sizeof operator.#include #includeint main(){void *ptr;printf("%d",sizeof(ptr));return 0;}Output: 2Explanation: Size of any type of near pointer in c is two byte.3. Generic pointer can hold any type of pointers like char pointer, struct pointer, array of pointer etc without any typecasting.Example:#includeint main(){char c='A';int i=4;void *p;char *q=&c;int *r=&i;p=q;printf("%c",*(char *)p);p=r;printf("%d",*(int *)p);return 0;}Output: A44. Any type of pointer can hold generic pointer without any typecasting.5. Generic pointers are used when we want to return such pointer which is applicable to all types of pointers. For example return type of malloc function is generic pointer because it can dynamically allocate the memory space to stores integer, float, structure etc. hence we type cast its return type to appropriate pointer type.Examples:1.char *c;c=(char *)malloc(sizeof(char));2.double *d;d=(double *)malloc(sizeof(double));3.Struct student{char *name;int roll;};Struct student *stu;Stu=(struct student *)malloc(sizeof(struct student));NULL pointer in c programmingNULL pointer:Literal meaning of NULL pointer is a pointer which is pointing to nothing. NULL pointer points the base address of segment.Examples of NULL pointer:1. int *ptr=(char *)0;2. float *ptr=(float *)0;3. char *ptr=(char *)0;4. double *ptr=(double *)0;5. char *ptr=\0;6. int *ptr=NULL;What is meaning of NULL?NULL is macro constant which has been defined in the heard file stdio.h, alloc.h, mem.h, stddef.h and stdlib.h as#define NULL 0Examples:What will be output of following c program?#include int main(){if(!NULL)printf("I know preprocessor");elseprintf("I don't know preprocessor"); return 0;}Output: I know preprocessorExplanation:!NULL = !0 = 1In if condition any non zero number mean true.What will be output of following c program?#include int main(){int i;static int count;for(i=NULL;i