Search Results

Search found 40165 results on 1607 pages for 'function pointers'.

Page 9/1607 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Pointers and Addresses in C

    - by Mohit
    #include "stdio.h" main() { int i=3,*x; float j=1.5,*y; char k='c',*z; x=&i; y=&j; z=&k; printf("\nAddress of x= %u",x); printf("\nAddress of y= %u",y); printf("\nAddress of z= %u",z); x++; y++;y++;y++;y++; z++; printf("\nNew Address of x= %u",x); printf("\nNew Address of y= %u",y); printf("\nNew Address of z= %u",z); printf("\nNew Value of i= %d",i); printf("\nNew Value of j= %f",j); printf("\nNew Value of k= %c\n",k); } Output: Address of x= 3219901868 Address of y= 3219901860 Address of z= 3219901875 New Address of x= 3219901872 New Address of y= 3219901876 New Address of z= 3219901876 New Value of i= 3 New Value of j= 1.500000 New Value of k= c The new address of variable y and z are same. How can two variables have same address and et have different values? Note: I used gcc compiler on Ubuntu 9.04

    Read the article

  • Are pointers primitive types in C++?

    - by Space_C0wb0y
    I was wondering about the last constructor for std::string mentioned here. It says: template<class InputIterator> string (InputIterator begin, InputIterator end); If InputIterator is an integral type, behaves as the sixth constructor version (the one right above this) by typecasting begin and end to call it: string(static_cast<size_t>(begin),static_cast<char>(end)); In any other case, the parameters are taken as iterators, and the content is initialized with the values of the elements that go from the element referred by iterator begin to the element right before the one referred by iterator end. So what does that mean if InputIterator is a char * ?

    Read the article

  • C++ Array of pointers: delete or delete []?

    - by Jasper
    Cosider the following code: class Foo { Monster* monsters[6]; Foo() { for (int i = 0; i < 6; i++) { monsters[i] = new Monster(); } } virtual ~Foo(); } What is the correct destructor? this: Foo::~Foo() { delete [] monsters; } or this: Foo::~Foo() { for (int i = 0; i < 6; i++) { delete monsters[i]; } } I currently have the uppermost constructor and everything is working okey, but of course I cannot see if it happens to be leaking... Personally, I think the second version is much more logical considering what I am doing. Anyway, what is the "proper" way to do this?

    Read the article

  • C++ pointers on example

    - by terence6
    I have a sample code : #include <iostream> #include <conio.h> using namespace std; int main () { int firstvalue = 5, secondvalue = 15; int * p1, * p2; p1 = &firstvalue; p2 = &secondvalue; cout << "1.p1: " << p1 << ", p2: " << p2 << endl; cout << "1.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p1 = 10; cout << "2.p1: " << p1 << ", p2: " << p2 << endl; cout << "2.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p2 = *p1; cout << "3.p1: " << p1 << ", p2: " << p2 << endl; cout << "3.*p1: " << *p1 << ", *p2: " << *p2 << endl; p1 = p2; cout << "4.p1: " << p1 << ", p2: " << p2 << endl; cout << "4.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p1 = 20; cout << "5.p1: " << p1 << ", p2: " << p2 << endl; cout << "5.*p1: " << *p1 << ", *p2: " << *p2 << endl; cout << "firstvalue is " << firstvalue << endl; cout << "secondvalue is " << secondvalue << endl; cout << "firstvalue is " << &firstvalue << endl; cout << "secondvalue is " << &secondvalue << endl; getch(); return 0; } And here's the output : 1.p1: 0041FB40, p2: 0041FB34 1.*p1: 5, *p2: 15 2.p1: 0041FB40, p2: 0041FB34 2.*p1: 10, *p2: 15 3.p1: 0041FB40, p2: 0041FB34 3.*p1: 10, *p2: 10 4.p1: 0041FB34, p2: 0041FB34 4.*p1: 10, *p2: 10 5.p1: 0041FB34, p2: 0041FB34 5.*p1: 20, *p2: 20 firstvalue is 10 secondvalue is 20 firstvalue is 0041FB40 secondvalue is 0041FB34 What is copied in the line "p1 = p2" ? Does p1 become reference to p2 or does it work in different way ?

    Read the article

  • Pointers in For loops

    - by Bobby
    Quick question: I am a C# guy debugging a C++ app so I am not used to memory management. In the following code: for(int i = 0; i < TlmMsgDB.CMTGetTelemMsgDBCount(); i++) { CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i); CMT_SINT32_Tdef id = telm->CMTGetPackingMapID(); ManualScheduleTables.SetManualMsg(i,id); ManualScheduleTables.SetManExec(i,false); } Am I leaking memory every iteration b/c of CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i);? The "CMTGetTelemetryMsg(int)" method returns a pointer. Do I have to "delete telm;" at the end of each iteration?

    Read the article

  • typedef to store pointers in C

    - by seriouslion
    The Size of pointer depends on the arch of the machine. So sizeof(int*)=sizeof(int) or sizeof(int*)=sizeof(long int) I want to have a custom data type which is either int or long int depending on the size of pointer. I tried to use macro #if, but the condition for macros does not allow sizeof operator. Also when using if-else, typedef is limited to the scope of if. if((sizeof(int)==sizeof(int *)){ typedef int ptrtype; } else{ typedef long int ptrtype; } //ptrtype not avialble here Is there any way to define ptrtype globally?

    Read the article

  • Assign pointers in objective C

    - by Tattat
    -(id)setBigObject:(BigObject *)abc{ self.wl = abc; abc.smallObject = self.smallObject; } I have a abc, which is a big Object, when the user pass the bigObject, abc. I assign to my wl value, so , I write "self.wl = abc;", but I want my smallObject assign to the abc's smallObject, so, I do "abc.smallObject = self.smallObject; " So, when I edit the smallObject in self, it will also changed in the abc's also? Am I right?

    Read the article

  • Function pointers usage

    - by chaitanyavarma
    Hi All, Why these two codes give the same output, Case 1: #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (x[0])(5,2); (x[1])(5,2); (x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10 Case 2 : #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (*x[0])(5,2); (*x[1])(5,2); (*x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10

    Read the article

  • Function pointers uasage

    - by chaitanyavarma
    Hi All, Why these two codes give the same output, Case - 1: #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (x[0])(5,2); (x[1])(5,2); (x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10 Case -2 : #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (*x[0])(5,2); (*x[1])(5,2); (*x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10

    Read the article

  • Pointers in C with binary file

    - by darkie15
    Hi All, I am reading the contents of the file using fread into an char array. But I am not sure why it is not getting printed in the output. Here is the code: void getInfo(FILE* inputFile) { char chunk[4]; int liIndex; for (liIndex = 0 ; liIndex < 4 ; liIndex++) { fread(chunk, sizeof(char), 4, inputFile); } printf("\n chunk %s", chunk); } Output prints nothing at all. Where am I going wrong? Regards , darkie

    Read the article

  • Proper way to reassign pointers in c++

    - by user272689
    I want to make sure i have these basic ideas correct before moving on (I am coming from a Java/Python background). I have been searching the net, but haven't found a concrete answer to this question yet. When you reassign a pointer to a new object, do you have to call delete on the old object first to avoid a memory leak? My intuition is telling me yes, but i want a concrete answer before moving on. For example, let say you had a class that stored a pointer to a string class MyClass { private: std::string *str; public: MyClass (const std::string &_str) { str=new std::string(_str); } void ChangeString(const std::string &_str) { // I am wondering if this is correct? delete str; str = new std::string(_str) /* * or could you simply do it like: * str = _str; */ } .... In the ChangeString method, which would be correct? I think i am getting hung up on if you dont use the new keyword for the second way, it will still compile and run like you expected. Does this just overwrite the data that this pointer points to? Or does it do something else? Any advice would be greatly appricated :D

    Read the article

  • Function keys for ASUS n56vm not working

    - by Lars
    i have installed Ubuntu 12.10 (64bits) (3.5.0-18 kernel) on an ASUS N56VM. Most fn+key are working except for: brightness keys (fn+f5/fn+f6) don't work. fn+c - gamma keys fc+v - camera fn+space - toggle speed. I really like, at least, to have the brightness keys working. Can you help? Best Regards $ dmesg | grep -i asus [ 0.000000] DMI: ASUSTeK COMPUTER INC. N56VM/N56VM, BIOS N56VM.206 04/13/2012 [ 0.000000] ACPI: RSDP 00000000cafcc000 00024 (v02 _ASUS_) [ 0.000000] ACPI: XSDT 00000000cafcc078 00074 (v01 _ASUS_ Notebook 01072009 AMI 00010013) [ 0.000000] ACPI: FACP 00000000cafdf858 000F4 (v04 _ASUS_ Notebook 01072009 AMI 00010013) [ 0.000000] ACPI: DSDT 00000000cafcc188 136CA (v02 _ASUS_ Notebook 00000013 INTL 20091112) [ 0.000000] ACPI: APIC 00000000cafdf950 00092 (v03 _ASUS_ Notebook 01072009 AMI 00010013) [ 0.000000] ACPI: FPDT 00000000cafdf9e8 00044 (v01 _ASUS_ Notebook 01072009 AMI 00010013) [ 0.000000] ACPI: ECDT 00000000cafdfa30 000C1 (v01 _ASUS_ Notebook 01072009 AMI. 00000005) [ 0.000000] ACPI: MCFG 00000000cafdfaf8 0003C (v01 _ASUS_ Notebook 01072009 MSFT 00000097) [ 0.000000] ACPI: SLIC 00000000cafdfb38 00176 (v01 _ASUS_ Notebook 01072009 ASUS 00000001) [ 0.000000] ACPI: HPET 00000000cafdfcb0 00038 (v01 _ASUS_ Notebook 01072009 AMI. 00000005) [ 0.000000] ACPI: BGRT 00000000cafe1090 00038 (v00 _ASUS_ Notebook 01072009 ASUS 00010013) [ 9.670500] asus_wmi: ASUS WMI generic driver loaded [ 9.671627] asus_wmi: Initialization: 0x1asus_wmi: BIOS WMI version: 7.9 [ 9.671673] asus_wmi: SFUN value: 0x6a0877<6>[ 9.672086] input: Asus WMI hotkeys as /devices/platform/asus-nb-wmi/input/input4 [ 9.732438] Registered led device: asus::kbd_backlight [ 9.733242] asus_wmi: Backlight controlled by ACPI video driver

    Read the article

  • ASP.NET – Function to Fill Month, Date and Year into Dropdown lists

    - by SAMIR BHOGAYTA
    public void fillMonthList(DropDownList ddlList) { ddlList.Items.Add(new ListItem("Month", "Month")); ddlList.SelectedIndex = 0; DateTime month = Convert.ToDateTime("1/1/2000"); for (int intLoop = 0; intLoop { DateTime NextMont = month.AddMonths(intLoop); //ddlList.Items.Add(new ListItem(NextMont.ToString("MMMM"), NextMont.Month.ToString())); ddlList.Items.Add(new ListItem(NextMont.ToString("MMMM"), NextMont.ToString("MMMM"))); } } public void fillDayList(DropDownList ddlList) { ddlList.Items.Add(new ListItem("Day", "Day")); ddlList.SelectedIndex = 0; int totalDays = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); for (int intLoop = 1; intLoop { ddlList.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString())); } } public void fillYearList(DropDownList ddlList) { ddlList.Items.Add(new ListItem("Year", "Year")); ddlList.SelectedIndex = 0; int intYearName = 1900; for (int intLoop = intYearName; intLoop { ddlList.Items.Add(new ListItem(intLoop.ToString(), intLoop.ToString())); } }

    Read the article

  • C - Complicated pointer declarations - help understanding

    - by Emmel
    In my burgeoning new self-education in the C language, I've come across a set of declarations that I do not understand how to read. I'd love for someone to break these down. I'll explain at the bottom where I got these examples from. 1. char (*(*x())[])() "x: function returning pointer to array[] of pointer to function returning char" - huh? 2. char (*(*x[3])())[5] "x: array[3] of pointer to function returning pointer to array[5] of char" - come again? 3. char **argv This I understand. "Pointer to pointer to char." But what I don't understand is -- what's the use case for a pointer to a pointer? Follow-up question: does anyone every use declarations this complex or is this just academic fun on the part of the authors of the examples I got this from? These examples are from section 5.12 of the K&R book. This is the first time I'm genuinely stumped by an explanation, in an otherwise well-written classic. Thanks.

    Read the article

  • [C++] Start a thread using a method pointer

    - by Michael
    Hi ! I'm trying to develop a thread abstraction (POSIX thread and thread from the Windows API), and I would very much like it to be able to start them with a method pointer, and not a function pointer. What I would like to do is an abstraction of thread being a class with a pure virtual method "runThread", which would be implanted in the future threaded class. I don't know yet about the Windows thread, but to start a POSIX thread, you need a function pointer, and not a method pointer. And I can't manage to find a way to associate a method with an instance so it could work as a function. I probably just can't find the keywords (and I've been searching a lot), I think it's pretty much what Boost::Bind() does, so it must exist. Can you help me ?

    Read the article

  • C++ function returning pointer, why does this work ? [migrated]

    - by nashmaniac
    So heres a simple c++ function what it does it take an array of characters as its argument and a integer n and then creates a new character array with only n elements of the array. char * cutString(char * ch , int n){ char * p = new char[n]; int i ; for(i = 0 ; i < n ; i++) p[i] = ch[i]; while(i <= n ){ p[i++] = '\0'; } return p ; } this works just fine but if I change char * p = new char[n]; to char p[n]; I see funny characters what happens ? What difference does the former make also p is a temporary variable then how does the function returns it alright ?

    Read the article

  • C++ and function pointers assessment: lack of inspiration

    - by OlivierDofus
    I've got an assessment to give to my students. It's about C++ and function pointers. Their skill is middle: it the first year of a programming school after bachelor. To give you something precise, here's a sample of a solution of one of 3 exercices they had to do in 30 minutes (the question was: "here's a version of a code that could be written with function pointers, write down the same thing but with function pointers"): typedef void (*fcPtr) (istream &); fcPtr ArrayFct [] = { Delete , Insert, Swap, Move }; void HandleCmd (const string && Cmd) { string AvalaibleCommands ("DISM"); string::size_type Pos; istringstream Flux (Cmd); char CodeOp; Flux >> CodeOp; Pos = AvalaibleCommands.find (toupper (CodeOp)); if (Pos != string::npos) { ArrayFct [Pos](Flux); } } Any idea where I could find some inspiration? Some of the students have understood the principles, even though it's very hard for them to write C++ code. I know them, I know they're clever, and I'm pretty sure they should be very good project managers. So, writing C++ code is not that important after all. Understanding is the most important part (IMHO). I'm wondering about maybe break the habits, and give half of the questions about the principle, or even better, give some sample in other language and ask them why it's better to use function pointers instead of classical programming (usually a big switch case). Any idea where I could look? Find some inspiration?

    Read the article

  • What is the underlying reason for not being able to put arrays of pointers in unsafe structs in C#?

    - by cons
    If one could put an array of pointers to child structs inside unsafe structs in C# like one could in C, constructing complex data structures without the overhead of having one object per node would be a lot easier and less of a time sink, as well as syntactically cleaner and much more readable. Is there a deep architectural reason why fixed arrays inside unsafe structs are only allowed to be composed of "value types" and not pointers? I assume only having explicitly named pointers inside structs must be a deliberate decision to weaken the language, but I can't find any documentation about why this is so, or the reasoning for not allowing pointer arrays inside structs, since I would assume the garbage collector shouldn't care what is going on in structs marked as unsafe. Digital Mars' D handles structs and pointers elegantly in comparison, and I'm missing not being able to rapidly develop succinct data structures; by making references abstract in C# a lot of power seems to have been removed from the language, even though pointers are still there at least in a marketing sense. Maybe I'm wrong to expect languages to become more powerful at representing complex data structures efficiently over time.

    Read the article

  • Dynamic creation of a pointer function in c++

    - by Liberalkid
    I was working on my advanced calculus homework today and we're doing some iteration methods along the lines of newton's method to find solutions to things like x^2=2. It got me thinking that I could write a function that would take two function pointers, one to the function itself and one to the derivative and automate the process. This wouldn't be too challenging, then I started thinking could I have the user input a function and parse that input (yes I can do that). But can I then dynamically create a pointer to a one-variable function in c++. For instance if x^2+x, can I make a function double function(double x){ return x*x+x;} during run-time. Is this remotely feasible, or is it along the lines of self-modifying code?

    Read the article

  • help Implementing Object Oriented ansi-C approach??

    - by No Money
    Hey there, I am an Intermediate programmer in Java and know some of the basics in C++. I recently started to scam over "C language" [please note that i emphasized on C language and want to stick with C as i found it to be a perfect tool, so no need for suggestions focusing on why should i move back to C++ or Java]. Moving on, I code an Object Oriented approach in C but kindda scramble with the pointers part. Please understand that I am just a noob trying to extend my knowledge beyond what i learned in High School. Here is my code..... #include <stdio.h> typedef struct per{ int privateint; char *privateString; struct per (*New) (); void (*deleteperOBJ) (struct t_person *); void (*setperNumber) ((struct*) t_person,int); void (*setperString) ((struct*) t_person,char *); void (*dumpperState) ((struct*) t_person); }t_person; void setperNumber(t_person *const per,int num){ if(per==NULL) return; per->privateint=num; } void setperString(t_person *const per,char *string){ if(per==NULL) return; per->privateString=string; } void dumpperState(t_person *const per){ if(per==NULL) return; printf("value of private int==%d\n", per->privateint); printf("value of private string==%s\n", per->privateString); } void deleteperOBJ(struct t_person *const per){ free((void*)t_person->per); t_person ->per = NULL; } main(){ t_person *const per = (struct*) malloc(sizeof(t_person)); per = t_person -> struct per -> New(); per -> setperNumber (t_person *per, 123); per -> setperString(t_person *per, "No money"); dumpperState(t_person *per); deleteperOBJ(t_person *per); } Just to warn you, this program has several errors and since I am a beginner I couldn't help except to post this thread as a question. I am looking forward for assistance. Thanks in advance.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >