Factsheet
Since Iโve started exploring C, Iโve realized that many programming languages rely on libraries built using C โbindings.โ I know C is fast and simple, so why donโt people just stick to using and improving C instead of creating new languages every couple of years?
I am currently working on an assignment in C where we are required to make a stack by simply using pointers.
I know the line: int *ptr = &val; declares ptr to be a "pointer to"(which is my interpretation of what asterisk * means in C) the "address of" the integer variable val.
When I want to create a double pointer, or a pointer to a pointer, I do so like:
int **ptr_ptr = &ptr; By setting ptr_ptr to a "pointer to" the address of pointer ptr.
When we use the asterisk anywhere other than in a declaration, it is usually referred to as dereferencing that pointer (I think), and grabbing the value that the pointer actually points to. This goes against my intuition that an asterisk means "pointer to".
Could anybody explain the proper meaning of the asterisk in C? Is it just that it means different things depending on how it is used (i.e. in a declaration versus anywhere else)?
Thanks!
As a european who learned english from speaking to and watching youtube videos of british and australian people online I always wondered why americans were so offended by a word that doesn't mean anything more "offensive" than calling someone a dick or an asshole. Especially considering how normalized the word is in australian or even scottish english.
Is there any particular reason for it?
It took me a lot of time to understand but it seems I finally got it.
All you have to do is add along second axis.
let's take :
np.c_[np.array([1,2,3]), np.array([4,5,6])]
But there isn't second axis. So we mentally add one.
so shape of both array becomes (3,1).
So resultant shape would be (3,1+1) which is (3,2). which is the shape of result -
array([[1, 4],
[2, 5],
[3, 6]])
Another ex.:
np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
shapes:
np.array([[1,2,3]]) = 1,3
np.array([[4,5,6]]) = 1,3
0 so we can think of it as [[0]] = 1,1
So result 1,3+1+1+3 = 1,8
which is the shape of result : array([[1, 2, 3, 0, 0, 4, 5, 6]])
Use IPython's ? syntax to get more information:
In [2]: c_?
Type: CClass
Base Class: <class 'numpy.lib.index_tricks.CClass'>
String Form:<numpy.lib.index_tricks.CClass object at 0x9a848cc>
Namespace: Interactive
Length: 0
File: /usr/lib/python2.7/dist-packages/numpy/lib/index_tricks.py
Docstring:
Translates slice objects to concatenation along the second axis.
This is short-hand for ``np.r_['-1,2,0', index expression]``, which is
useful because of its common occurrence. In particular, arrays will be
stacked along their last axis after being upgraded to at least 2-D with
1's post-pended to the shape (column vectors made out of 1-D arrays).
For detailed documentation, see `r_`.
Examples
--------
>>> np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
array([[1, 2, 3, 0, 0, 4, 5, 6]])