a or o to make Paint or Point.
playing hooky
Find the missing letter F-O-R T-A-R P-U-_
linear search array for key and return index of firstoccurrence.intfindInteger(int array[], int asize, int key) {int* p = array;while (asize-- && *p != key)++p;return p - array;}
Example: int *p= (int *)-1; *p= 0;
int const *p declares a 'p' pointer, that points to a constant integer
T
Any letter- x, n, p.... YOU CHOOSE!
#include<stdio.h> #include<malloc.h> int* getpoly(int); void showpoly(int *,int); int* addpoly(int *,int,int *,int); int* mulpoly(int *,int,int *,int); int main(void) { int *p1,*p2,*p3,d1,d2,d3; /*get poly*/ printf("\nEnter the degree of the 1st polynomial:"); scanf("%d",&d1); p1=getpoly(d1); printf("\nEnter the degree of the 2nd polynomial:"); scanf("%d",&d2); p2=getpoly(d2); printf("Polynomials entered are\n\n"); showpoly(p1,d1); printf("and\n\n"); showpoly(p2,d2); /*compute the sum*/ d3=(d1>=d2?d1:d2); p3=addpoly(p1,d1,p2,d2); printf("Sum of the polynomials is:\n"); showpoly(p3,d3); /*compute product*/ p3=mulpoly(p1,d1,p2,d2); printf("Product of the polynomials is:\n"); showpoly(p3,d1+d2); } int* getpoly(int degree) { int i,*p; p=malloc((1+degree)*sizeof(int)); for(i=0;i<=degree;i++) { printf("\nEnter coefficient of x^%d:",i); scanf("%d",(p+i)); } return(p); } void showpoly(int *p,int degree) { int i; for(i=0;i<=degree;i++) printf("%dx^%d + ",*(p+i),i); printf("\b\b\b "); printf("\n"); } int* addpoly(int *p1,int d1,int *p2,int d2) { int i,degree,*p; degree=(d1>=d2?d1:d2); p=malloc((1+degree)*sizeof(int)); for (i=0;i<=degree;i++) if((i>d1) && (i<=d2)) *(p+i)=*(p2+i); else if((i>d2) && (i<=d1)) *(p+i)=*(p1+i); else *(p+i)=*(p1+i)+*(p2+i); return(p); } int* mulpoly(int *p1,int d1,int*p2,int d2)/* this is the function of concern*/ { int i,j,*p; p=malloc((1+d1+d2)*sizeof(int)); for(i=0;i<=d1;i++) for(j=0;j<=d2;j++) p[i+j]+=p1[i]*p2[j]; return(p); }
You cannot physically convert variables of one type to another type, you can only cast them to create a new type (a new variable), providing the new type is covariant with the existing type. int i = 100; // int variable int* p = &i; // pointer to int The indirect value of p is i (100) while the direct value of p is the address of i. And because p is a variable, it has an address of its own. Thus converting the pointer p to an int can be done in one of three ways: int j = *p; // assign indirect value of p to j (thus j==100). int k = (int) p; // cast the address stored in p and assign to k (k==address of i) int l = (int) &p; // cast the address of p and assign to l (l==address of p)
int *p, *q; p = (int*) malloc (100 * sizeof (int)); q = (int*) calloc (100, sizeof (int)); Note that p is left in an uninitialised state whereas q is initialised with the value zero.
int main (void) or int main(int a, char **p)
J