Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Liquid Web Cloud VPS Hosting

10,939 questions

14,849 answers

573 users

What is the difference between char array[] and char *p in C

1 Answer

0 votes
#include <stdio.h> 

int main(void) 
{ 
    char arr[] = "c c++ java php";
	char *p = "c c++ java php";
	
    printf("1. %s\n", arr);
	printf("2. %s\n\n", p);
	
	printf("3. %d %d\n", (int)sizeof(arr), (int)sizeof(p));
	printf("4. %p %p\n", arr, p);
	printf("5. %p %p\n", &arr, &p);
	printf("6. %c %c %c\n\n", arr[0], p[0], *(p + 0));
	
	arr[0] = 'x';
	//p[0] = 'x'; Error
    printf("7. %s\n", arr);
	printf("8. %s\n\n", p);
	
	printf("9. %c %c %c\n\n", arr[13], p[13], *(p + 13)); // last char
	printf("10. %c %c %c\n\n", arr[14], p[14], *(p + 14)); // arr[14]=null (end string) p[14]=?
	printf("11. %c %c %c\n\n", arr[15], p[15], *(p + 15)); // arr[15]=? (out of index) p[15]=?
	
	
	//arr++; Error
	p++;
    printf("12. %s\n", arr);
	printf("13. %s\n\n", p);
	

     
    return 0; 
} 
   
   
   
/*
run:
   
1. c c++ java php
2. c c++ java php

3. 15 8
4. 000000000062FE10 0000000000404030
5. 000000000062FE10 000000000062FE08
6. c c c

7. x c++ java php
8. c c++ java php

9. p p p

10.

11.   1 1

12. x c++ java php
13.  c++ jaava php
 
*/

 




answered Aug 11 by avibootz
edited Aug 11 by avibootz
...