Questions

Can you compare void pointers?

Can you compare void pointers?

@jl987: It is not possible to compare values pointed by void * pointers without expilcitly telling the compiler how to compare them. The compiler does not know it. Only you know how to do that. In the simplest case you will have to tell the compiler what types these values have by specifying the exact type in the cast.

Can you compare pointers in C?

Pointer Comparison in C In C language pointers can be compared if the two pointers are pointing to the same array. All relational operators can be used for pointer comparison, but a pointer cannot Multiplied or Divided.

Can we compare pointer?

We can compare pointers if they are pointing to the same array. Relational pointers can be used to compare two pointers. Pointers can’t be multiplied or divided.

READ ALSO:   Why reptiles make the best pets?

Can you compare void pointers in C?

The void pointer isn’t different from pointers to other types in this regard. You can’t compare them using > , >= , < , <= without incurring undefined behavior unless they point to elements in the same array or to an imaginary element immediately following the array.

Can you dereference a void pointer?

1) void pointers cannot be dereferenced. For example the following program doesn’t compile.

What happens when you compare pointers?

When two pointers are compared, the result depends on the relative locations in the address space of the objects pointed to. If two pointers to object types both point to the same object, or both point one past the last element of the same array object, they compare equal.

How do you compare two strings using pointers?

String comparison by using pointers

  1. #include
  2. int stringcompare(char*,char*);
  3. int main()
  4. {
  5. char str1[20]; // declaration of char array.
  6. char str2[20]; // declaration of char array.
  7. printf(“Enter the first string : “);
  8. scanf(“\%s”,str1);
READ ALSO:   How do you know if a company is doing layoffs?

What happens when you dereference a void pointer?

You can not dereference a void pointer because it doesn’t have a type, first you need to cast it (int *)lVptr , then dereference it *(int *)lVptr . A void pointer is just that, a pointer to a void (nothing definable).