Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-28-2010, 06:38 AM   #1
LQ Newbie
Registered: May 2009
Location: kolkata,india
Distribution: fedora
Posts: 6

Rep: Reputation: 0
Explain the output(pointers)

explain me the output please .As far as my knowledge. a is a character type pointer variable and its size should be 4 bytes irrespective of what its pointing to.but i get a result =50.
*a is the value of a[0] and its size is rightly 1 byte.
but how can the size of that variable change to 4 byte when i just add 7 to it(although i don't store the added result anywhere)

int main(){
	char a[50];
	printf("\n%d  ",sizeof(a));
	printf("\n%d  ",sizeof(*a));
	printf("\n%d  ",sizeof(*a+7));
	return 0;

Last edited by ishandutta2007; 01-28-2010 at 06:42 AM.
Old 01-28-2010, 07:19 AM   #2
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Originally Posted by ishandutta2007 View Post
but i get a result =50.
"a" is an array of 50 chars, so size is correct.
Try this:
int main(){
	char a[50];
	char* b = a;
	printf("\n%d  ",sizeof(a));
	printf("\n%d  ",sizeof(b));
	return 0;

Last edited by SigTerm; 01-28-2010 at 10:09 AM.
Old 01-28-2010, 09:25 AM   #3
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
*a+7 means (*a)+7. And char+int=int.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
please explain the output of the printf dina3e Linux - Newbie 14 10-15-2008 12:03 PM
C pointers : What will be the output? duryodhan Programming 15 11-28-2006 12:40 AM
Could someone please explain this nmap output? stardotstar Linux - Networking 0 02-07-2005 11:02 PM
explain the output suchi_s Programming 9 11-08-2004 10:07 AM
explain the output c pragti Programming 10 05-28-2004 01:17 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:19 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration