Jump to content

[Solved]giving unexpected output


Recommended Posts

Nothing great,  you have to just add '&' symbol before the variable name you are passing to the function.  That's it.  by adding &,  you are passing the location of the variable to the function instead of function.  Search your text book for some examples :P

why search?I'll ask my teacher to explain that to me again !!
Link to comment
Share on other sites

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

why search?I'll ask my teacher to explain that to me again !!

Whats there to ask your teacher? Its easy. In call by value you pass the values of the variables you are passing and they are stored in local variables in the function. So as soon as you exit the body of the function the local variables of the function gets destroyed and along with that the result of your calculation also gets destroyed. But if you call by reference then the address of the variable are passed to the function. So any alteration of the variables made in the function directly affects the passed variables. Its as simple as that.

Link to comment
Share on other sites

@CrackUC I forgot to mention i saw 1more bad programming practice in your program. You should not use void main() as your main function. Instead use int main(). Although 99% of the compilers wont object to this but void main() is actually a non-standard implementation of main(). The C and C++ standard defines main to be of the following 2 forms-- i. int main() ii. int main(int arg c,char *argv) So its better to use main in the above mentioned two forms.

Link to comment
Share on other sites

@CrackUC

I forgot to mention i saw 1more bad programming practice in your program. You should not use void main() as your main function. Instead use int main(). Although 99% of the compilers wont object to this but void main() is actually a non-standard implementation of main(). The C and C++ standard defines main to be of the following 2 forms--

i. int main()

ii. int main(int arg c,char *argv)

So its better to use main in the above mentioned two forms.

Than i'l go with int main 1st one.!! I'm learning C as i don have talent in any thing in Pc the things i know are useless And if i go to any job they'll reject me as i know nothing though i'm in 10th but still it matters for me!! i'm learning C for idea of programming and i think i'll probly learn java too in home itself!! but i'll be going with VB after it my course is just 15 classes more after that i'll pratise badly in vacations After that VB what u say?Vb or any other?
Link to comment
Share on other sites

Than i'l go with int main 1st one.!! I'm learning C as i don have talent in any thing in Pc the things i know are useless And if i go to any job they'll reject me as i know nothing though i'm in 10th but still it matters for me!! i'm learning C for idea of programming and i think i'll probly learn java too in home itself!! but i'll be going with VB after it my course is just 15 classes more after that i'll pratise badly in vacations After that VB what u say?Vb or any other?

You're in class 10 only so dont think about jobs now. Just enjoy life while you can :D. And after you finish C you should definitely start C++. There are lots of new things in C++ that aren't in C. Once you master C++, learning java will be a piece of cake. After you learn java if you do want to learn any other language then i would suggest SQL & PL/SQL. SQL is easy. You can learn SQL in a single day. There is nothing to it. But PL/SQL is extremely difficult. It'll take a lot of time for you to learn it.

Link to comment
Share on other sites

You're in class 10 only so dont think about jobs now. Just enjoy life while you can :D. And after you finish C you should definitely start C++. There are lots of new things in C++ that aren't in C. Once you master C++, learning java will be a piece of cake. After you learn java if you do want to learn any other language then i would suggest SQL & PL/SQL. SQL is easy. You can learn SQL in a single day. There is nothing to it. But PL/SQL is extremely difficult. It'll take a lot of time for you to learn it.

Dude as u know c is a lil kinda boor.(not always but most of times)As many things gets uncleared.Still i put my max effort to make them clear My eacher said VB would be interesting but still i'll go what u says as u r more expert than him too(i think).

BTw why its said not to global variables?

Link to comment
Share on other sites

And how about PHP asp.net?And difference b/w c++ and java?just syntax or any other too? And  i'm learning languages as i'm weak in studies.Weak means i no devotes it time stil from 10th i study 1 hour daily as i want science in 11th. + languages would be a back support for me if i won't get addmition in good collage!! i don't want to strugle in life for money atleast..

Link to comment
Share on other sites

Dude as u know c is a lil kinda boor.(not always but most of times)As many things gets uncleared.Still i put my max effort to make them clear My eacher said VB would be interesting but still i'll go what u says as u r more expert than him too(i think).

BTw why its said not to global variables?

You think C is boring? Wait till you study database concepts. You'll fall asleep :P. I would not recommend VB to you because its not used in the industry much. And dont say C is difficult. If you think C is difficult then PL/SQL will make you go mad.

Link to comment
Share on other sites

And how about PHP asp.net?And difference b/w c++ and java?just syntax or any other too? And  i'm learning languages as i'm weak in studies.Weak means i no devotes it time stil from 10th i study 1 hour daily as i want science in 11th. + languages would be a back support for me if i won't get addmition in good collage!! i don't want to strugle in life for money atleast..

PHP and asp.net is good if you want to be a web designer. But there isn't much money in web designing. But if web designing is your hobby you can definitely learn HTML and PHP. They are very simple languages. It wont take long to learn them. But don't think about languages now and study hard. You can learn languages any time but study comes first.

Link to comment
Share on other sites

You think C is boring? Wait till you study database concepts. You'll fall asleep :P. I would not recommend VB to you because its not used in the industry much. And dont say C is difficult. If you think C is difficult then PL/SQL will make you go mad.

Dude my file handling chapter is left by databases u meant same or other thing :-/ pl/sql is used in industries?And for what purposes? U r a comunication engineer i think..So hw come these languages came in ur job  :-/
Link to comment
Share on other sites

BTw why its said not to global variables?

It is recommended not to use global variables for data security purposes. If a variable is global then it can be accessed by any function in the program. So any unwanted function may accidentally change the value of your global variable by mistake. So it is recommended not to use global variables.

Link to comment
Share on other sites

It is recommended not to use global variables for data security purposes. If a variable is global then it can be accessed by any function in the program. So any unwanted function may accidentally change the value of your global variable by mistake. So it is recommended not to use global variables.

#-o than it will be a great loop whole for hackers  :-O
Link to comment
Share on other sites

Dude my file handling chapter is left by databases u meant same or other thing :-/ pl/sql is used in industries?And for what purposes? U r a comunication engineer i think..So hw come these languages came in ur job  :-/

No by database i meant a subject called DBMS(Database Management System). And yes pl/sql is extensively used in the industry. Its used to write programs for database management systems like oracle, MS SQL Server, MySQL Server etc. I handle telecom projects where you have to design software for telecom companies. You need software for many functions over there.

Link to comment
Share on other sites

No by database i meant a subject called DBMS(Database Management System). And yes pl/sql is extensively used in the industry. Its used to write programs for database management systems like oracle, MS SQL Server, MySQL Server etc. I handle telecom projects where you have to design software for telecom companies. You need software for many functions over there.

its in C?if yes i'll ask my teacher to teach me that too!! just confirm me its in C .

Not exactly but yes your program will be vulnerable.

Hmm.. suppose u r a hacker so hw u'll steal the data in programe xplain hw u'll hack into it?it will be more clear for me!!

#include<stdio.h>

#include<conio.h>

char pin;

void enter()

{

printf("enter your secret PIN");

scanf("%ch",pin);

}

int main()

{

printf("Your pin has been stored safely");

getch();

}

Suppose u have hack the pin in character stored by user hw u'll do that?

Link to comment
Share on other sites

its in C?

No. DBMS is not a language. PL/SQL is the language.

Suppose u have hack the pin in character stored by user hw u'll do that?

It can be done by a technique called memory injection. Well in this particular case we dont have to inject anything into memory but we generally do require to do that. Anyways for memory injection you can use a software called Cheat Engine. Using Cheat Engine you can read the values of the variables of your program at run time.

Link to comment
Share on other sites

Lolz i just compiled that program that program stops responding after i enter pin here's the program anindya please point out the mistake!

#include<stdio.h>

#include<conio.h>

int pin;

int enter()

{

printf("enter your secret PIN:");

scanf("%d",pin);

}

int display()

{

printf("Your pin has been stored safely");

}

int main()

{

    enter();

    display();

getch();

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...