-1

I have been trying to learn C as a programming language, and have been trying to solve sample problems on site like LeetCode in C programs. When I was reading over some of the skeleton code that was provided as a function header for a problem on LeetCode that I want to solve in C, the function header had asterisks post fixing some of the types, specifically like this:

int* twoSum(int* nums, int numSize, int target, int* returnSize) {
   /* Code goes here */
}

After doing a fair bit of reading, I learned that prefixing a variable with an asterisk when declaring a variable reserves the variable as a pointer, but I have not been able to find anything about what it means when the type specifier itself is post fixed with an asterisk.

Fuse
  • 1
  • 2

1 Answers1

3

The spaces there don't matter.

int* nums is identical to int *nums. So are int * nums and int*nums.

All four of these declare nums as pointer to int.

It's a matter of style preference (though I wouldn't use that last one), with no effect on the generated code.

Thomas Jager
  • 4,836
  • 2
  • 16
  • 30