473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

pointer

WHAT IS DIFFERENT BETWEEN THIS.
char *ptr="hello";
char ptr[]="hello";
Nov 18 '06 #1
8 1224
//what Is Different Between Overloading And Overlapping .
Nov 18 '06 #2
#include<iostream.h>
#include<conio.h>
int sum(double,double);
int sum(int,int);
void main()
{
clrsscr();
cout<<sum(12.456,34.677);
cout<<sum(13,56);
getch();
}
/*
THIS IS RIGHT OR NOT
*/
Nov 18 '06 #3
//what is different between .
struct student s;//student is user define data type
struct student *s;
Nov 18 '06 #4
//what is different between .
struct student s;//student is user define data type
struct student *s;//
struct student *s;
s=new student;
s=new student[5];
s=new student[];
Nov 18 '06 #5
horace1
1,510 Expert 1GB
WHAT IS DIFFERENT BETWEEN THIS.
char *ptr="hello";
char ptr[]="hello";
some examples
Expand|Select|Wrap|Line Numbers
  1.     char *s = "hello";            // "hello" is a constant, s is pointer at it   
  2.     char a[30] = "hello";         // define an array, initialise it with    "hello"
  3.     *(s+2) = 'X';                 // ERROR! change second element of char*pointed to by s 
  4.                                   //   would give run time segmentation error
  5.     a[2] = 'X';                  // OK change second element of array a
  6.     s=a;                         // point s at array a
  7.     *(s+2) = 'Z';                // OK change second element of string pointed to by , i.e. a[2]
  8.  
Nov 18 '06 #6
horace1
1,510 Expert 1GB
#include<iostream.h>
#include<conio.h>
int sum(double,double);
int sum(int,int);
void main()
{
clrsscr();
cout<<sum(12.456,34.677);
cout<<sum(13,56);
getch();
}
/*
THIS IS RIGHT OR NOT
*/
you have overloaded function sum(), one takes two double parameters and the other takes two int paramters. So when you call sum() in main() it calls the corect version. There were a few minor bugs in your code but this version works
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. double sum(double,double);
  4. int sum(int,int);
  5. int main()
  6. {
  7. //clrsscr();    // ** not available on all compilers
  8. cout<<sum(12.456,34.677) << endl;
  9. cout<<sum(13,56) << endl;
  10. getch();
  11. }
  12. double sum(double x,double y) { return x + y; }
  13. int sum(int x,int y) { return x + y; }
  14.  
when run it gives
47.133
69


note if you call sum() so
Expand|Select|Wrap|Line Numbers
  1. cout<<sum(13,56.0) << endl;
  2.  
the compiler will not know which version to call and gives error message
Expand|Select|Wrap|Line Numbers
  1. 10 C:\tue\x1.cpp call of overloaded `sum(int, double)' is ambiguous 
  2.  note C:\tue\x1.cpp:3 candidates are: double sum(double, double) 
  3.  note C:\tue\x1.cpp:3                 int sum(int, int) 
  4.  
Nov 18 '06 #7
pragatiswain
96 Expert
Simple words :

char *ptr="hello"; //ptr contains the location address of hello.
char ptr[]="hello"; // ptr contains hello.

Please correct me, if I am wrong
Nov 18 '06 #8
horace1
1,510 Expert 1GB
Simple words :

char *ptr="hello"; //ptr contains the location address of hello.
char ptr[]="hello"; // ptr contains hello.

Please correct me, if I am wrong
in
char *ptr="hello";
"hello" is a constant and ptr contains the address of it
you cannot change the contents of "hello"

in
char ptr[]="hello";
"hello" is an array and ptr contains the address of it
You can change the contents of hello
Nov 18 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
35
by: tuko | last post by:
Hello kind people. Can someone explain please the following code? /* Create Storage Space For The Texture */ AUX_RGBImageRec *TextureImage; /* Line 1*/ /* Set The Pointer To NULL...
16
by: junky_fellow | last post by:
According to Section A6.6 Pointers and Integers (k & R) " A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
16
by: aegis | last post by:
Given the following: int a = 10; int *p; void *p1; unsigned char *p2; p = &a;
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
8
by: Martin Jørgensen | last post by:
Hi, "C primer plus" p.382: Suppose we have this declaration: int (*pa); int ar1; int ar2; int **p2;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.