Questions tagged [char-pointer]

Character Pointer is a data type which holds the address of a primitive charter type variable.

Character pointer can point to a memory address which holds a character value in the form of ASCII Code. A static character array also decays into a char pointer. A Char pointer can be allocated memory dynamically using this syntax.

char *char_ptr = new char ;

It can also be allocated a whole char array and it points to the first index of that dynamic array.

char *char_ptr = new char [10] ;

Typically, as with other pointers, a char pointer takes 4 bytes of memory in the system. Its properties match those of other pointer types with slightly different behavior. The compound operation of assignment and output are allowed on char pointer. If a char pointer points to a cstring, these operations are possible on it which are not legal on any other pointer type.

char *char_ptr = "hello world" ;
cout << *char_ptr ;
171 questions
-3
votes
1 answer

Caesar Cipher using char * ? c++

So i am trying to use the Ceasar Cipher with char *'s, I've written a simple function out like this: char * Encrypt(char * s, int k) { char * c = s; for(int i = 0; i < strlen(s); i++) c[i] += k; return c; } that seems to look…
JeffCoderr
  • 283
  • 1
  • 4
  • 16
-3
votes
1 answer

Printing array of char pointers

I am trying to read two lines from a file using array of pointers. However, I am not getting anything on screen. I have tried searching online, but could not solve the problem. Here is my code that I have written using Netbeans on mac. int main(int…
Sankalps
  • 23
  • 4
-3
votes
1 answer

Parse from char array to an char pointer in c++

I have a problem in my code. I want to parse a char array to an char pointer; How can i do it? Example code : char tmp[1000]; char *temp; gets(tmp); How can i parse the char tmp into char *temp? Regards,
-4
votes
1 answer

Print unicode and text values of char pointer

I am new to c++, I am trying to print some values on console. I am using below code for this std::cout << "text : " << text.latin1().data() <
Pavan Tiwari
  • 3,077
  • 3
  • 31
  • 71
-4
votes
1 answer

Why it is giving error "segmentation fault"?

I want to input two strings at different memory locations but after taking the first input it shows an error "segmentation fault(core dumped"). I am not getting what's wrong with this code. #include #include using namespace…
Naresh
  • 155
  • 1
  • 9
-6
votes
1 answer

Unexpected output of printf for a string in C

Case 1: When I take string input, it successfully gives the output, writing this piece of code: #include int main() { char *str; scanf("%s",&str); printf("%s",&str); return 0; } Case 2: On the other hand, it throws a…
1 2 3
11
12