Pages

Sunday, October 28, 2018

C String - Predict output


Predict Program Output Based on C String


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


Program-1


#include <stdio.h> 
int main () 

    char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
    printf("Greeting message: %s\n", greeting ); 
    return 0; 
}

Program-2


#include "stdio.h" 
int main() 

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


Program-3


#include<stdio.h>
#include<string.h>
int main()
{
    char str1[20] = "C Program";
    char str2[20] = "C Practicals";
    printf("%s\n", strcpy(strcat(str1, str2), str2));
    return 0;
}

Program-4


#include<stdio.h>
#include<string.h>
int main()
{
    printf("%d", strlen("01234567"));
    return 0;
}


Program-5


#include<stdio.h>
int main()
{
    printf(10 + "C Program Practicals");
    return 0;
}

Click here to check ANSWER

Read more interesting programs at C Program Practicals - Question Bank.


No comments:

Post a Comment