BM Balmiki Mandal 23 May 2023 25 views 0 comments C Programming

Difference Between Integer Pointers and Character Pointers in C

Understanding the Contrast: Integer Pointers vs. Character Pointers in C

The main difference between an integer pointer and a character pointer in C is the size of the data they point to. An integer pointer is a pointer to an integer, which is typically 4 bytes in size. A character pointer is a pointer to a character, which is typically 1 byte in size.

This difference in size can be seen when you try to dereference the pointers. For example, the following code will print the value of the integer pointed to by ptr:

int i = 10;
int *ptr = &i;
printf("%d\n", *ptr);

Print the address of the character pointed to by ptr:

char c = 'a';
char *ptr = &c;
printf("%p\n", ptr);

In addition to the size difference, there are also some other differences between integer pointers and character pointers. For example, integer pointers can be used to perform arithmetic operations, while character pointers cannot.

Finally, it is important to note that a character pointer can be used to point to a string of characters. This is because a string is simply a sequence of characters, and each character is stored in a single byte.

Here are some examples of how integer pointers and character pointers can be used:

  • An integer pointer can be used to iterate through an array of integers.
  • A character pointer can be used to read a line of text from the console.
  • A character pointer can be used to write a string to a file.

Overall, integer pointers and character pointers are both useful tools in C. The choice of which type of pointer to use will depend on the specific task at hand.

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

C Bitwise Operators Explained: 10 Practice Programs with Output

E.1: Bitwise vs. Logical Operators#include<stdio.h> int main(void){ int x=7,y=19; printf("%d %d ",x&y...

AG Anvesh G 29 Nov 2026
Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026