Search
 
SCRIPT & CODE EXAMPLE
 

C

pointer arithmetic in c

#include <stdio.h>

int main()
{ // pointer Arithmetic
    printf("
Pointer Arithmetic
");
    int i, *ptr;
    int num[] = {10, 100, 200};
    // assign array address to pointer
    ptr = num;
    // value of ptr = address of num
    printf("
    Value of ptr -----  %x
", ptr);

    for (i = 0; i < 3; i++)
    {

        printf("    Address of num[%d] = %x
", i, ptr);
        printf("    Value of num[%d] = %d
", i, *ptr);
        ptr++; // next address space  Jumps by 4 due to the size of an int in memory.
    }
	
    // String Array arithmetic
   	// I'm not recommending you do this 
    printf("

String Arithmetic

");
    char *str[12] = {"C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"};

    printf("    Array value at index 11 is %s
", str[11]);
    // address of array at index
    printf("    Address of array at index 0 %x
", str[0]);
    // address of array
    printf("    Address of array %x
", *str);
    // increases the memory address by one.
    str[0]++;
    // address of array
    printf("    Address of array after array has been incremented by one %x
", *str);

    return 0;
Comment

PREVIOUS NEXT
Code Example
C :: addition of matrix 
C :: how to get file size in c 
C :: how to change background color in c programming 
C :: getchar in c 
C :: print float in c 
C :: C program for float division of numbers 
C :: create node in c 
C :: How to copy one string into another in C 
C :: how to sort an int array in c 
C :: absolute value of intel intrinsic 
C :: do while loop in c 
C :: c program to find minimum of 5 numbers using conditional operator in c 
C :: how to arrange a 2d array based on string length in c 
C :: stack and heap memorym in ram 
C :: scan c 
C :: relational operators in c 
C :: mc dropout pytorch 
C :: how to take input in c 
C :: printing words lemgthwise in c 
C :: can we use logical operators in switch c 
C :: C static libraries (Indexing an archive) 
C :: resto de division recursiva 
C :: how to link flexslider 
C :: windows block application au demarrage regegit 
C :: disable gnu++11 option 
C :: c limit value range 
C :: 50 north main 07522 
C :: mettre int dans string c % 
C :: using tables as arguments in c++/c 
C :: C fgets() and puts() 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =