Pages

Friday, October 26, 2018

C Pointers - Predict output


Predict Program Output Based on C Pointers

Output of following C Programs are not very simple. These are simple but very interesting top c programs asked during viva and interviews.


Program-1


#include<stdio.h> 
int main() 

    int x = 10, *y, *z; 
    y = &x;  
    z = y; 
    printf("%d, %d, %d", x, *y, *z); 
    return 0; 
}

Program-2

#include "stdio.h" 
int main() 

    char str[] = { 'A', 'B', 'C', 'D' }; 
    char *p = &str[0]; 
    *p++;
    printf("%c ", *p);
    *p++;
    printf("%c ", *p);


Program-3

#include "stdio.h" 
int main() 

    int marks[] = { 50, 60, 70, 80 }; 
    int *p = &marks[0]; 
    *p++;
    printf("%d ", *p);
    *p = *p+2;
    printf("%d ", *p);


Program-4

#include <stdio.h>
int main() 

    int marks[] = { 50, 60, 70, 80 }; 
    int *p = &marks[0]; 
    *p++;
    printf("%d ", *p);
    *p++;
printf("%d ", *p);



Program-5

#include <stdio.h> 
int main() 

    int *ptr; 
    *ptr = 5; 
    printf("%d", *ptr); 
    return 0; 
}

Check your Answer here... 

No comments:

Post a Comment