473,789 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's the position of pointers

When I began to learn C, My teacher told me that pointer is the most
difficult part of C, it makes me afraid of it. After finishing C
program class, I found that all the code I wrote in C contains little
pointers, obviously I avoid using them.
A few days ago when I was reading a book about programming, I was told
that pointers are the very essence of C language, if I couldn't use it
well, I'm a bad programmer, it's a big shock.
So now I'm wondering: what's the exact position of pointers in C? Is
it really necessary to learn how it works again?
Sep 11 '08
69 3219
On 13 Sep, 20:17, Richard Heathfield <r...@see.sig.i nvalidwrote:
sh.vi...@gmail. com said:
/* Puzzle code*/
void X(?????){
???????
}
int main(int cnt, char *aa[]){
int a;
a = 5;
X(??????); * *//line # 5
printf("\n Value of a is %d",a);
retrun 0;
}
---------------Desired OUTPUT -----------
Value of a is 20
Problem Statement
-----------------------
In the above code, at all the places where you see "?????" you have to
write some C Code.
you have to write the code such that without modifying the variable
"a" in main, value of "a" becomes 20. That is the output of program
when run is as shown in desired output.
Once you finish this, you will realize that there are many cases/
problems which cann;t be solved without using the pointers.

void X(int ignore){
* * * * int puts(const char *);
* * * * void exit(int);
* * * * puts("Value of a is 20");
* * * * exit(0);

}
You used the string literal "Value of a is 20",
which was converted to a pointer, and the
literal text "const char *" in your declaration
of puts, so I think it it not quite accurate
to say that you have 'solved' this puzzle
without using pointers.

I think this is a decent "puzzle" for
a person confused by C to think about.

Sep 14 '08 #31
Keith Thompson said:

<snip>
You can obfuscate by being overly verbose as well as by being overly
terse.
Yes, "too much" of anything is bad, just as "too little" of anything is
bad, by definition. But that doesn't mean my examples were overly verbose.
Clearly you thought they were. I disagree.
If I see either
int main(int lI0O0, char **lI0OO)
or
int main(int ArgumentCount, char **ArgumentVecto r)
I have to stop and think about what those two identifiers mean.
In the first case, I agree with you. In the second, I would be very
surprised to find a man of your calibre struggling with this.
In
both cases, I'm going to have to realize that what they really *mean*
is argc and argv.
No, in both cases, you're going to have to realise that what they really
*mean* is an argument count and an argument vector. Neither argc nor argv
carries any intrinsic meaning. Yes, I agree it's a convention, and yes, I
usually use those names myself, but any reasonable substitute will do just
as well.
[...]
>>I don't know where this bizarre habit of putting the "\n" at the
beginning of a line rather than at the end came from.

Neither do I, but it is well-established, rather like void main.

I think it's a Windows thing, but I don't know why.
It isn't. It was already well-established in 1989, and Windows 3.0 (the
first "popular" version of Windows) didn't come out until 1990 or so.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 14 '08 #32
William Pursell said:
On 13 Sep, 20:17, Richard Heathfield <r...@see.sig.i nvalidwrote:
>sh.vi...@gmail .com said:
<snip>
>>
Once you finish this, you will realize that there are many cases/
problems which cann;t be solved without using the pointers.

void X(int ignore){
int puts(const char *);
void exit(int);
puts("Value of a is 20");
exit(0);

}

You used the string literal "Value of a is 20",
which was converted to a pointer, and the
literal text "const char *" in your declaration
of puts, so I think it it not quite accurate
to say that you have 'solved' this puzzle
without using pointers.
I'm astonished that it took almost a day for this nit to be picked.
Nevertheless (if we can lose the decls by assuming the proper inclusion of
<stdio.hand <stdlib.h>) I think I've demonstrated that it's possible to
solve this problem without /learning/ about pointers - i.e. without going
to the trouble of finding out all about * and & and so on. Therefore, it
is not a good problem, because it isn't fit for purpose. It's like asking
people to write a program to sort some data, where the intent is for them
to devise a sorting algorithm for themselves (as an intellectual
exercise), but through either a misunderstandin g or sheer bloodymindednes s
a programmer submits nothing more sophisticated than a call to qsort (and
with a certain amount of justification, too).

Poor specifications make for unintended solutions.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 14 '08 #33
Richard Heathfield <rj*@see.sig.in validwrites:
Keith Thompson said:

<snip>
>You can obfuscate by being overly verbose as well as by being overly
terse.

Yes, "too much" of anything is bad, just as "too little" of anything is
bad, by definition. But that doesn't mean my examples were overly verbose.
Clearly you thought they were. I disagree.
>If I see either
int main(int lI0O0, char **lI0OO)
or
int main(int ArgumentCount, char **ArgumentVecto r)
I have to stop and think about what those two identifiers mean.

In the first case, I agree with you. In the second, I would be very
surprised to find a man of your calibre struggling with this.
I don't have to struggle with it. What I would have to struggle with
(just a little bit, just briefly) is why the programmer chose to use
those names rather than the almost universally conventional "argc" and
"argv".

And, for that matter, if I saw a reference to ArgumentCount in the
body of main without having noticed the unconventional declaration, I
*would* have to struggle with it. And the parameter list probably
wouldn't be the first place I'd look. If I see a reference to argc, I
don't have to look for the declaration (unless I suspect the author of
being deliberately perverse).
>In
both cases, I'm going to have to realize that what they really *mean*
is argc and argv.

No, in both cases, you're going to have to realise that what they really
*mean* is an argument count and an argument vector. Neither argc nor argv
carries any intrinsic meaning. Yes, I agree it's a convention, and yes, I
usually use those names myself, but any reasonable substitute will do just
as well.
Do you *ever* use any other names? If so, why?

The names "argc" and "argv" are not mandated by the language, as, say,
"int" and "main" are. Nevertheless, they're effectively what the
arguments to main are called. Calling them ArgumentCount and
ArgumentVector isn't quite as bad as:

#define ProgramEntryPoi nt main
#define DefaultIntegerT ype int
#define NoArguments void

DefaultIntegerT ype ProgramEntryPoi nt(NoArguments) { /* ... */ }

but it's a very similar kind of obfuscation.

[...]

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 14 '08 #34
Keith Thompson <ks***@mib.orgw rites:
Richard Heathfield <rj*@see.sig.in validwrites:
>Keith Thompson said:

<snip>
>>You can obfuscate by being overly verbose as well as by being overly
terse.

Yes, "too much" of anything is bad, just as "too little" of anything is
bad, by definition. But that doesn't mean my examples were overly verbose.
Clearly you thought they were. I disagree.
>>If I see either
int main(int lI0O0, char **lI0OO)
or
int main(int ArgumentCount, char **ArgumentVecto r)
I have to stop and think about what those two identifiers mean.

In the first case, I agree with you. In the second, I would be very
surprised to find a man of your calibre struggling with this.

I don't have to struggle with it. What I would have to struggle with
(just a little bit, just briefly) is why the programmer chose to use
those names rather than the almost universally conventional "argc" and
"argv".
Agreed.

In the same way I think "if(0==funcCall (t))" is too clever for its own
good and a tad pretentious.

And

p = malloc(2 * sizeof h[i])

is liable to confuse many over

p = malloc(2 * sizeof h[0])

or even better

p = malloc(sizeof structArr[0]);
Sep 14 '08 #35
[argc, argv]

Keith Thompson said:

<snip>
Do you *ever* use any other names? If so, why?
No, I can't say I do, being a bit of a traditionalist - but I have no
particular reason not to, other than mere tradition.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 14 '08 #36
Keith Thompson wrote:
sh******@gmail. com writes:
[...]
>>>Once you finish this, you will realize that there are many cases/
problems which cann;t be solved without using the pointers.
It's probably better just to read about pointers in some good tutorial
or reference work, such as K&R2.
Did that come after seeing Richard's Solution or you think there still
can be a solution without using call by reference here. I agree call
be reference is actually call be value only in "C" but want to explore
you more on this.

My point was merely that reading a good tutorial is a more effective
way to learn about pointers than reading a single puzzle. I haven't
really thought about other ways to "cheat" on your puzzle.
I think it's the puzzle format that is the problem. I am an experienced
C programmer with absolutely no uncertainty about what pointers are, how
to use them, and why they are useful. But I found the wording of that
puzzle so obscure that it took me 20-30 seconds to figure out what he
was driving at. I think that someone who's still in the position to ask
"what are pointers good for?" is extremely unlikely to figure it out.

Code which solves that puzzle would have been better provided as an
example, than asked for as a solution. With the example in hand as a
prototype, you could then pose a puzzle which asks for a more
complicated answer that is based on the same concept.
Sep 14 '08 #37
It's like asking
people to write a program to sort some data, where the intent is for them
to devise a sorting algorithm for themselves (as an intellectual
exercise),
You analogy is perfect but incomplete, please check below

intent
------------
to devise sorting algortithm for themesleves <==to make someone
understand the *importance* of pointers (remember it is the importance
of pointers rather than pointers itself)

task given
----------------
given a data to be sorted <====given a problem to be solved

constraints
----------------
complexity of algortihm should be O(nlogn) or lower <===solution
should have code written only at places of ??????

expectation from person
----------------
he will come up with an algorithm which probably can be any of the
algorithm with complexity O(nlogn) such as merge sort, heap sort or if
exists in the world for all conditions in O(n) complexity or even in
O(1) <===he will come up with a solution for problem using pointers
or may be if exists in the world without using pointers in "C" but
solution must meet constraints

In good amount of cases, After solving the problem one will realize
that
----------------
he has used an approach which is nothing but well known algorithm
"quicksort" or any other O(nlogn) complexity sorting algorithm
<======person has used nothing but pointers and with the given
constraints there is no solution without using pointers

but through either a misunderstandin g or sheer bloodymindednes s
a programmer submits nothing more sophisticated than a call to qsort (and
with a certain amount of justification, too).
But than there is someone who
-------------------------------------
calls the qsort instead of trying to find the steps of algorithm
<=====uses constant string to print the solution

and still thinks that he has
--------------------------------------
devised the best answer <===solved the problem without using
pointers.

unfortunately he later finds that
---------------------------------------------------
data was already sorted and hence the complexity of algorithm has
reached complexity O(n*n) which doesn't meet the constraint <====he
has used nothing but still a pointer to a constant string.
>
Poor specifications make for unintended solutions.
sometimes specifications are not as flawed as solutions are

--
vIpIn
Sep 14 '08 #38
On Sep 14, 5:15 pm, sh.vi...@gmail. com wrote:
It's like asking
people to write a program to sort some data, where the intent is for them
to devise a sorting algorithm for themselves (as an intellectual
exercise),

You analogy is perfect but incomplete, please check below
Whose analogy? Please leave attribute lines untouched.

<snip>
Sep 14 '08 #39
I think it's the puzzle format that is the problem. I am an experienced
C programmer with absolutely no uncertainty about what pointers are, how
to use them, and why they are useful.
may be language was not as good, i have already accepted that.
But I found the wording of that
puzzle so obscure that it took me 20-30 seconds to figure out what he
was driving at.
I will try to be better in futrue. In fact i tried to improve the
wording of
problem also in one of my earlier posts.
I think that someone who's still in the position to ask
"what are pointers good for?" is extremely unlikely to figure it out.

Code which solves that puzzle would have been better provided as an
example, than asked for as a solution.
in the original post, person has mentioned that "I found that all the
code
I wrote in C contains little pointers, obviously I avoid using them "

so i assumed that he has at least used pointers in past and he will be
able to
realize the importance in the attempt to find the solution for this
problem.
prototype, you could then pose a puzzle which asks for a more
complicated answer that is based on the same concept.
yea that can also be a good approach too. I ll take a note of it.
at the end of all this discussion i hope the person, who needs to
be benefited, one who posted the query originally, is getting
benefited.

thnx all for your valuable inputs
--
vIpIn
Sep 14 '08 #40

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

Similar topics

669
26234
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
12
4215
by: slartybartfast | last post by:
I'm new(ish) to css, comfortable using tables, but trying real hard to move away. Please see http://84.9.125.31/developer/css_test/test5.html NB This issue is with IE & Opera - I've tried IE 6&7 and both have the same result. It works fine in FF. Thanks to Petr Stanicek for the original example. As you can see the table is 800px wide in the middle column and it's vertical position is affected by the amount of text in the left or right...
89
5774
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the right thing to use for every var that holds the number of or size in bytes of things. * size_t should only be used when dealing with library functions.
0
10404
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.