Generic Pointer in C Programming
Generic
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.
Technical Help Desk is a platform where you can investigate the problems related to programming languages like C, C++, C# , Java and others like Data Structures, Software Engineering, Data Base , SQL , and many more ..... By Rajveer Choudhary.
| Pattern 1. | *** ** * ** *** |
| Code: | #include <stdio.h> main() { int i,x,j; for (i=2; i>=-2;i--) { x = 1 + 2*abs(i); for (j=1;j<=x;j++) printf("*"); printf("\n"); } |
| Pattern 2. | RAJVEER A E J E V V E J E A REEVJAR |
| Code: | #include<conio.h> #include<string.h> void main() { char str[20]; int i,j,k,len; printf("Enter the String: "); gets(str); len=strlen(str); puts(str); printf(""); for(i=1;i<len-1;i++) { printf("%c",str[i]); for(j=0;j<len-2;j++) printf(" "); printf("%c\n",str[len-i-1]); } strrev(str); puts(str); } |
| Pattern 3. | * ** *** ** * |
| Code: | #include <stdio.h> main() { int i,x,j; for (i=2; i>=-2;i--) { x = 1 + abs(i);
for (j=1;j<=x;j++) printf(" ");
for (j=1;j<=x;j++) printf("*"); printf("\n"); } |
| Pattern 4. | 1 01 101 0101 |
| Code: | #include<stdio.h> #include<conio.h> void main() { int i,j; int count = 1; clrscr(); for(i=1;i<=4;i++) { for(j=1;j<=i;j++) { printf("%d",(i+j+1)%2); } printf("\n"); } getch(); } |
| Que 1. | What is an lvalue? |
| Ans. | An lvalue is an expression to which a value can be assigned.
The lvalue expression is located on the left side of an assignment statement,
whereas an rvalue is located on the right side of an assignment statement. Each
assignment statement must have an lvalue and an rvalue. The lvalue expression
must reference a storable variable in memory. It cannot be a constant.
For instance, the following lines show a few examples of lvalues: |
| int x;
int* p_int; x = 1; *p_int = 5; |
|
| The variable x is an integer, which is a storable location in memory. Therefore,
the statement x = 1 qualifies x to be an lvalue.
1 = x Here compiler generate the error because the left value is contact which cannot be assigned. |
|
| Que 2. | What is an rvalue? |
| Ans. | rvalue can be defined as an expression that can be assigned to an lvalue. The rvalue appears on the right side of an assignment statement. Unlike an lvalue, an rvalue can be a constant or an expression, as shown here: |
| int x, y; x = 1; /* 1 is an rvalue; x is an lvalue */ y = (x + 1); /* (x + 1) is an rvalue; y is an lvalue */ |
|
| An assignment statement must have both an lvalue and an rvalue.Therefore, the
following statement would not compile because it is missing an rvalue: int x; x = void_function_call() /* the function void_function_call() returns nothing */ If the function had returned an integer, it would be considered an rvalue because it evaluates into something that the lvalue, x, can store. |
|
| Que 3. | What are enumerations? |
| Ans. | They are a list of named integer-valued constants.
Example: enum color { black , orange=4,yellow, green, blue, violet }; This declaration defines the symbols “black”, “orange”, “yellow”, etc. to have the values “1,” “4,” “5,” … etc. The difference between an enumeration and a macro is that the enum actually declares a type, and therefore can be type checked. |
| Que 4. | What are register variables? What are the advantages of using register variables? |
| Ans. | If a variable is declared with a register storage class, it is known as register
variable. The register variable is stored in the cpu register instead of main memory. Frequently used variables are declared as register variable as it’s access time is faster. |
| For Eg.
register int x=90; |
|
| Que 5. | What do you know about Storage classes? |
| Ans. | A storage class defines the scope (visibility) and life time of variables and/or
functions within a C Program.
There are following storage classes which can be used in a C Program |
|