This method is useful when you do not have any address assigned to the pointer. A null pointer always contains value 0. In C programming , a void pointer is also called as a generic pointer.
It does not have any standard data type. A void pointer is created by using the keyword void. It can be used to store an address of any variable. A pointer is said to be a wild pointer if it is not being initialized to anything.
These types of C pointers are not efficient because they may point to some unknown memory location which may cause problems in our program and it may lead to crashing of the program.
One should always be careful while working with wild pointers. Below table shows the arithmetic and basic operation that can be used when dealing with C pointers. Traditionally, we access the array elements using its index, but this method can be eliminated by using pointers. Pointers make it easy to access each array element. Adding a particular number to a pointer will move the pointer location to the value obtained by an addition operation.
Since p currently points to the location 0 after adding 1, the value will become 1, and hence the pointer will point to the memory location 1. We can manipulate strings using pointers. This pointer in C example explains this section.
Skip to content. What is Pointer in C? What You Will Learn. Types of Pointers in C Following are the different Types of Pointers in C : Null Pointer We can create a null pointer by assigning null value during the pointer declaration.
Report a Bug. Previous Prev. Next Continue. Home Testing Expand child menu Expand. But really, what is a type? The gist of it is that a type is way to determine how data in memory is supposed to be interpreted. A variable of the type char represents a character. A variable of the type int represents an integer. The pure form is quite unusable because you can't dereference it. But really, they're pointers, and therefore a data-type in their own right. Your title asks "What is the data type of pointer variables?
The answer is simple: a pointer variable is of some pointer type. For example, given:. The body of your question asks whether "a pointer is a data type or not". By any reasonable definition of the phrase "data type", pointer types are data types. The C standard never defines the phrase "data type", but it does use it informally in several places. It happens that none of the uses of the phrase "data type" in the standard refer to pointer types, but that doesn't tell us anything.
The standard says that all types are either function types or object types. Object types are further divided into a number of categories: integer types, array types, structure types, union types, pointer types, etc.
A pointer type can be a pointer to an object type or a pointer to a function type. It can be a pointer to an incomplete object type; as of the standard, incomplete types are classified as object types. Another ambiguity in your question is your use of the word "pointer". The word "pointer" by itself commonly refers to an object of pointer type, but it can also refer to a value of pointer type for example, the standard says that malloc returns a pointer.
It's better to use "pointer" as an adjective rather than as a noun, so you can have:. A pointer type is an object type.
A pointer object is an object; an object is defined by the standard as a "region of data storage in the execution environment, the contents of which can represent values". So a pointer object is a region of data storage. Following your Link 2 , some random person on the Internet wrote that "Pointers are simply a variable that hold an address so one could argue that a pointer is a data type, but it is not defined as a data type per "The C Programming Language".
I'm curious: why would you think that a pointer type wouldn't be considered a data type? For example in the C Standard there is no formal definition of the term data type. There are object types and function types. At the same time pointers are derived types constructed from object and function types. Thus in general case pointers are data types that is they are data types that are constructed from object and function types.
So there is some contradiction in the Standard. On the one hand pointers are objects because they occupy memory and the memory represents their values. So we may say that pointers are object types. On the other hand pointers are considered as derived types from object types.
In my opinion it would be better if there would be explicitly written in the Standard that pointers are derived object types or derived function types. Pointer is a data-type. So we can create pointer variables which can hold the address of memory location. There is no one single pointer type; a pointer to int is a different type from a pointer to char , which is a different type from a pointer to double , which is a different type from a pointer to a element array of int , which is a different type from a pointer to an element array of int , etc.
Your question probably refers to the "data type of a pointer", in contrast to the data type of the pointed-to data, which is what one would understand in the first place. Which typically means that it's the same size as a pointer". Of course, its size is platform-dependant: 32 bit or 64 bit. So don't transport this variable across platforms of different size.
Please note, to assign it you have to cast from the 'specific' pointer type, to the 'generic' one:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. What is the data type of pointer variables?
Ask Question. Asked 6 years, 11 months ago. Active 1 year, 3 months ago. Viewed 14k times. I refereed the following link, Link1 Link 2 In the above link1 it was mentioned in answer that " Pointers are of pointer type ". I just need to know is pointer is a data type or not. No one has answered that question in single word. It is datatype or not? This is the second link which i refered says that Pointers are simply a variable that hold an address so one could argue that a pointer is a data type, but it is not defined as a data type per "The C Programming Language".
Improve this question. Community Bot 1 1 1 silver badge. It depends on what you mean by "data type". It's certainly a type , and indeed an object type , as opposed to a function or reference type , but neither language formally defines the term "data type".
Informally, it's a type that can hold some data an address , so yes, it is a data type. I'm not sure that the phrase "data type" has any different meaning from "type" — Bill Lynch. BillLynch: Is a function type a "data type"? I'd say no.
On some architectures they may be represented as a pair of values page :offset. Show 4 more comments. Active Oldest Votes. Improve this answer. JohnBode: didn't I mention that?
0コメント