[Solved] Using make_shared with char[] or int[] [closed]

Visual Studio 2015 doesn’t support the C++17 standard. Prior to C++17 standard you can’t have the std::shared_ptr<T[]> pointer. But even in C++17 the std::make_shared function doesn’t support array types so you would have to use the boost::make_shared instead. Another alternative is to use the unique pointer in combination with the std::make_unique which does support the … Read more

[Solved] What happened to local pointer? [closed]

In foo() and foo2() you are returning pointers to local variables. These locals have automatic storage and it is undefined behavior to use a pointer to them once they go out of scope. Therefor p and p2 contain nothing useful. It might work, it might not. I can’t understand your question very well, so I … Read more

[Solved] What does char *x = “geeksquiz” mean?

Does this mean that x holds the address of first element of the string,i.e, the character ‘g’ ? Yes. is it the placeholder %s that’s instructing the printf to print the string literals ? Yes. To be more specific, %s is not limited for string literals. It is for printing null terminated srings – which … Read more

[Solved] What is the difference between a double and short type in C? [closed]

From Wikipedia: Short: Short signed integer type. Capable of containing at least the [−32,767, +32,767] range;[3][4] thus, it is at least 16 bits in size. The negative value is −32767 (not −32768) due to the one’s-complement and sign-magnitude representations allowed by the standard, though the two’s-complement representation is much more common. Double: Real floating-point type, … Read more

[Solved] Run-time error: *** glibc detected *** [closed]

Let’s look at the first two lines of your code: str = (char *) malloc(15); strcpy(str, “63tczfqV4nqB2YnH9iFJbGvGyyDkvK341rrj0G0mo1PEYniOVHejVIFIQnJzHSSMRbuyGMCZ4M5HFMV4y1q4QgYqyxp2XkTjxaolKTkaw1r25S2Emz061tw1”); At this point, you have broken the rules of the C language. strcpy will write past the end of str which causes undefined behavior. Everything that happens after this point is kinda up in the air. 5 solved … Read more

[Solved] What does below pointer syntax mean [duplicate]

The three are same. The only differences are, The position of the asterisk and the whitespace around them(which is done according to one’s preference) The string literals “blah” could be stored in the same memory location or different locations. From the C11 standard, 6.4.5 String literals […] It is unspecified whether these arrays are distinct … Read more

[Solved] Assigning/Casting integers to pointers

#define int int* will replace int *p, q as int* *p, q. So Here p is double pointer to int and q is of type int. For example consider the below program of your same logic in char #include<stdio.h> #define char char* main() { char *p,q; printf(“%d, %d\n”, sizeof(p), sizeof(q)); } Output is 4, 1 … Read more

[Solved] Pointer variable of a linked list: difference between the variable, reference to the variable, and pointer to the variable [closed]

No! You’re talking some mix-up of C and C++. This is C code. C does not have references. The & operator can be applied to objects in order to retrieve their address in memory, yielding a pointer, in both C and C++. It ain’t got nothing to do with references. Even in C++. In C++, … Read more

[Solved] Same thing like C++ pointer in Java

Java’s pointers (so called by the language specification, while I believe Java programmers mostly know them as “references”) do not support pointer arithmetic. And Java has no way to do pointer arithmetic. If you want to do such low-level stuff in Java, one way is to use JNI (the Java Native Interface) to access code … Read more

[Solved] C. for loop with chars

This char s[]=”TvNnFs”,*p; where s is an array of characters and p is character pointer, is looks like below s[0] s[1] s[2] s[3] s[4] s[5] s[6] —————————————— | T | v | N | n | F | s | \0 | —————————————— s 0x100 0x101 0x102 0x103 0x104 0x105 0x106.. (assume 0x100 is base … Read more