Sponsored Content
Top Forums Programming How to get the sizeof char pointer Post 302322322 by fpmurphy on Wednesday 3rd of June 2009 10:49:09 AM
Old 06-03-2009
Quote:
which is terminated by a null byte by convention.
To clarify, from ISO C99 Sect 7.1.1, a string is a "contiguous sequence of characters terminated by and including the first null character".

Quote:
your two calls to sizeof will always return 4 (size of a pointer).
This is only true if you are on a platform whose programming model is such that a pointer is 32 bits. One such common programming model is ILP32 (Microsoft Windows, 32-bit Linux) where the size of an integer, long and pointer are all 32 bits. Another common programming model is LP64 (64-bit Linux) where the size of an integer is 32 bits but the size of a long and a pointer is 64 bits.
 

10 More Discussions You Might Find Interesting

1. Programming

sizeof

we know that sizeof never returns zero when used with structure then why in this case it is returning zero struct foo { char c; }; void main() { struct foo f; cout<<sizeof(f); } i am working on solaris 5.8 isn't the above function should return the size of empty structure (7 Replies)
Discussion started by: ramneek
7 Replies

2. Programming

Regarding char Pointer

Hi, char *s="yamaha"; cout<<s<<endl; int *p; int i=10; p=&i; cout<<p<<endl; 1) For the 1st "cout" we will get "yamaha" as output. That is we are getting "content of the address" for cout<<s. 2) But for integer "cout<<p" we are getting the "address only". Please clarify how we are... (2 Replies)
Discussion started by: sweta
2 Replies

3. Programming

Adding a single char to a char pointer.

Hello, I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it: char* getext(char *file) { char *extension; int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies

4. Programming

pass a pointer-to-pointer, or return a pointer?

If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it: (1) one is to pass a pointer-to-pointer parameter, like: int my_malloc(int size, char **pmem) { *pmem=(char *)malloc(size); if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies

5. Programming

sizeof an array of structure without using 'sizeof' operator

Hi All, is it possible to find out the size of an array of structures ( without using 'sizeof' operator). The condition is we have the array of structure instant but we are not aware of the elements inside the structure. Can someone help me out? Thanks in advance. (18 Replies)
Discussion started by: rvan
18 Replies

6. Programming

Doubts regarding sizeof() operator

Hi, There are some bewildering sizeof() questions I have in my mind. Could anyone shed some light on this? int main() { printf("%d\n", sizeof(main)); // Ans: 1 } That is, the sizeof() a function identifier though it is treated internally as a pointer gives 1 byte always, why? ... (5 Replies)
Discussion started by: royalibrahim
5 Replies

7. Programming

sizeof(object) in C++

Hi, I have defined the class and call the sizeof(object to class) to get the size. # include <iostream> # include <iomanip> using namespace std; class sample { private: int i; float j; char k; public: sample() { } (2 Replies)
Discussion started by: ramkrix
2 Replies

8. Programming

help with char pointer array in C

i have an array like #define NUM 8 .... new_socket_fd = accept(socket_fd, (struct sockaddr *) &cli_addr, &client_length); char *items = {"one", "two", "three", "four", "five", "six", "seven", "eight"}; char *item_name_length = {"3", "3", "5", "4", "4", "3", "5", "5"}; ... (1 Reply)
Discussion started by: omega666
1 Replies

9. Programming

Compiler/Runtime uses of sizeof

Ignoring other considerations for a moment and in general ... Would there be a difference in result (dot oh or execution) of: A. strncpy( a, b, sizeof(a) ); vs. B. c = sizeof(a); strncpy( a, b, c ); My general understanding is (at least I think my understanding is) that... (10 Replies)
Discussion started by: GSalisbury
10 Replies

10. Programming

Segmentation fault when I pass a char pointer to a function in C.

I am passing a char* to the function "reverse" and when I execute it with gdb I get: Program received signal SIGSEGV, Segmentation fault. 0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72 72 *q = *p; Attached is the source code. I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies
stdint(5)							File Formats Manual							 stdint(5)

NAME
stdint - integer types SYNOPSIS
DESCRIPTION
This header file defines sets of integer types having specified widths and corresponding sets of macros. It also defines macros that spec- ify limits of integer types corresponding to types defined in other standard headers. Since not all implementations are required to support all of the integer sizes defined in this manual page, the proper way to see if a par- ticular size of an integer is supported on the current implementation is to test the symbol that defines its maximum value. For example, if tests false, then that implementation does not support 64-bit unsigned signed integers. This header file defines the following integer data types for 8, 16, 32, and 64 bits. largest signed integer data type supported by implementation 8-bit signed integer 16-bit signed integer 32-bit signed integer 64-bit signed integer largest unsigned integer data type supported by implementation 8-bit unsigned integer 16-bit unsigned integer 32-bit unsigned integer 64-bit unsigned integer The following two data types are signed and unsigned integer data types that are large enough to hold a pointer. A pointer can be moved to or from these data types without corruption. signed integer type that is large enough to hold a pointer unsigned integer type that is large enough to hold a pointer This header file defines the following integer data types for determining the most efficient data types to use for integer values on a par- ticular implementation. most efficient signed integer data type supported by implementation most efficient signed integer of at least 8 bits most efficient signed integer of at least 16 bits most efficient signed integer of at least 32 bits most efficient signed integer of at least 64 bits most efficient unsigned integer data type supported by implementation most efficient unsigned integer of at least 8 bits most efficient unsigned integer of at least 16 bits most efficient unsigned integer of at least 32 bits most efficient unsigned integer of at least 64 bits This header file defines the following integer data types for compatibility with systems that do not fit the 16-bit or 32-bit word size model. These data types define the signed and unsigned integers of at least 8, 16, 32, and 64 bits. smallest signed integer of at least 8 bits smallest signed integer of at least 16 bits smallest signed integer of at least 32 bits smallest signed integer of at least 64 bits smallest unsigned integer of at least 8 bits smallest unsigned integer of at least 16 bits smallest unsigned integer of at least 32 bits smallest unsigned integer of at least 64 bits The following macros define the minimum and maximum values that can be stored in the above data types. minimum value that can be stored in the largest integer data type maximum value that can be stored in the largest signed integer data type maximum value that can be stored in the largest unsigned integer data type minimum value that can be stored in the most efficient integer data type maximum value that can be stored in the most efficient signed integer data type maximum value that can be stored in the most efficient unsigned integer data type minimum value that can be stored in an data type minimum value that can be stored in an data type minimum value that can be stored in an data type minimum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type" minimum value that can be stored in an data type minimum value that can be stored in an data type" minimum value that can be stored in an data type minimum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type minimum value that can be stored in an data type minimum value that can be stored in an data type minimum value that can be stored in an data type minimum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type maximum value that can be stored in an data type The following macros specify the maximum and minimum limits of integer types corresponding to types defined in other standard headers. All these values are implementation defined. minimum value that can be stored in data type maximum value that can be stored in data type minimum value that can be stored in data type maximum value that can be stored in data type maximum value that can be stored in data type minimum value that can be stored in data type maximum value that can be stored in data type minimum value that can be stored in data type maximum value that can be stored in data type The following macros expand to integer constant expressions suitable for initializing objects that have integer types corresponding to types defined in header. Macros For Minimum-Width Integer Constant Expressions The macro expands to an integer constant expression corresponding to the type The macro expands to an integer constant expression corresponding to the type For example, if is a name for the type then might expand to the integer constant Macros For Greatest-Width Integer Constant Expressions The following macro expands to an integer constant expression having the value specified by its argument and the type The following macro expands to an integer constant expression having the value specified by its argument and the type FILES
SEE ALSO
inttypes(5), standards(5), <stddef.h>, <wchar.h>, <signal.h>. stdint(5)
All times are GMT -4. The time now is 02:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy