473,545 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why multiplication not allowed?

Hi,

Why multiplication of pointers is not allowed?
Till now I only know this, but not the reason why!

PS: As a rule, I searched the FAQ, but could not
find an answer.

--
Vijay Kumar R Zanvar
My Home Page - http://www.geocities.com/vijoeyz/
Nov 14 '05 #1
87 11147
"Vijay Kumar R Zanvar" <vi*****@hotpop .com> writes:
Why multiplication of pointers is not allowed?
Till now I only know this, but not the reason why!


What would multiplication of pointers mean?
Nov 14 '05 #2

"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
"Vijay Kumar R Zanvar" <vi*****@hotpop .com> writes:
Why multiplication of pointers is not allowed?
Till now I only know this, but not the reason why!


What would multiplication of pointers mean?


#include <stdio.h>
#include <stdlib.h>

int
main ( void )
{
int i = 10;
int *k = &i, *j = &i;

k = k * j;
return EXIT_SUCCESS;
}

This gives an error:

ptr_mul.c: In function `main':
ptr_mul.c:10: error: invalid operands to binary *
Nov 14 '05 #3
"Vijay Kumar R Zanvar" <vi*****@hotpop .com> writes:
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
"Vijay Kumar R Zanvar" <vi*****@hotpop .com> writes:
Why multiplication of pointers is not allowed?
Till now I only know this, but not the reason why!
What would multiplication of pointers mean?


#include <stdio.h>
#include <stdlib.h>

int
main ( void )
{
int i = 10;
int *k = &i, *j = &i;

k = k * j;


You mean
*k = *k * *j;
In other words, multiply `int's, not pointers to `int's.
return EXIT_SUCCESS;
}


The difference between pointers and their referents is pretty
fundamental. Have you considered reading a textbook or taking a
class?
--
"I don't have C&V for that handy, but I've got Dan Pop."
--E. Gibbons
Nov 14 '05 #4

"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
int i = 10;
int *k = &i, *j = &i;

k = k * j;


You mean
*k = *k * *j;
In other words, multiply `int's, not pointers to `int's.


Is the following code wrong? I mean, does it do the same?
int* k =&i
int* j=&i
k* = k* * j*

(It seems to me more readable than the above. I come from Pascal background)


Nov 14 '05 #5
Vijay Kumar R Zanvar wrote:
"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
"Vijay Kumar R Zanvar" <vi*****@hotpop .com> writes:

Why multiplication of pointers is not allowed?
Till now I only know this, but not the reason why!


What would multiplication of pointers mean?


The question Ben is asking is, what would you propose pointer
multiplication do? How would you define the operation? I can't think of
any way in which multiplying a pointer by any other value would be
useful or even meaningful.

Your question is somewhat like asking "why can't I assign to a
function?" or "why can't I take the square root of a struct?" There's
just no logical reason why you *should* be able to.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #6
"Vijay Kumar R Zanvar" <vi*****@hotpop .com> wrote:
Why multiplication of pointers is not allowed?


Jack lives at Westmoreland Street 12, London SW6 4E8. Jill lives at
Rossinistraat 27b, 1287 CZ Amsterdam. Please multiply these addresses
and let us know the result.

Richard
Nov 14 '05 #7
Julian Maisano wrote:

"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
> int i = 10;
> int *k = &i, *j = &i;
>
> k = k * j;
You mean
*k = *k * *j;
In other words, multiply `int's, not pointers to `int's.


Is the following code wrong? I mean, does it do the same?
int* k =&i
int* j=&i
k* = k* * j*


Yes, it's wrong; no, it doesn't do the same thing; and no, it's not legal
syntax. The last line parses as:

k *= k * *j *

That is, multiply k (a pointer!) by the contents of j, multiply /that/ by
heaven knows what, and then use the result to multiply by k again,
assigning the result to k.
(It seems to me more readable than the above. I come from Pascal
background)


In C, the dereferencing operator comes before the pointer. C programmers are
accustomed to this syntax, and find it perfectly readable.
--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #8
Richard Heathfield wrote:
Julian Maisano wrote:
Is the following code wrong? I mean, does it do the same?
int* k =&i
int* j=&i
k* = k* * j*


Yes, it's wrong; no, it doesn't do the same thing; and no, it's not legal
syntax. The last line parses as:

k *= k * *j *


It doesn't parse that way. The whitespace between '*' and '=' is
significant, so

i* = j;

is also a syntax error.

Jeremy.
Nov 14 '05 #9
Jeremy Yallop wrote:
Richard Heathfield wrote:
Julian Maisano wrote:
Is the following code wrong? I mean, does it do the same?
int* k =&i
int* j=&i
k* = k* * j*
Yes, it's wrong; no, it doesn't do the same thing; and no, it's not legal
syntax. The last line parses as:

k *= k * *j *


It doesn't parse that way. The whitespace between '*' and '=' is
significant,


Indeed it is. Oops, sorry, darn and heck. (More or less in that order.)
so

i* = j;

is also a syntax error.


Right.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2263
by: Soeren Sonnenburg | last post by:
Hi all, Just having started with python, I feel that simple array operations '*' and '+' don't do multiplication/addition but instead extend/join an array: a= >>> b= >>> a+b
9
7990
by: Ralf Hildebrandt | last post by:
Hi all! First of all: I am a C-newbie. I have noticed a "strange" behavior with the standart integer multiplication. The code is: void main(void)
11
4853
by: mjdeesh_hi | last post by:
How can we perfom multiplication programatically without using + or * operator. Can any one help out in this one. Jagadeesh.
11
5211
by: Skybuck Flying | last post by:
Hello, type Tbig = array of byte; vAddTable : array of array of byte; // = value // = transport/carry vMulTable : array of array of byte;
1
9136
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void recMultiply(int i, int j, float a, int k, int l, float b, int x, int y, float c, int s); int i, j, k, s, matrixsize, blocksize, jj, kk, power, bsize;...
0
7415
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7440
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5344
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.