Monday, November 5, 2018

String - Predict Output-2

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 str[] = "%d";
    str[1] = 'c';
    printf(str, 97);
    return 0;
}

Program-2

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

Program-3

#include<stdio.h>
int main()
{
    char *names[] = { "AAA", "BBB", "CCC"};
    int i;
    char *temp;
   
  temp = names[0];
    names[0] = names[1];
    names[1] = temp;
   
  for(i=0; i<=2; i++)
        printf("%s ", names[i]);
    return 0;
}

Program-4

#include<stdio.h>
#include<string.h>
int main()
{
    char name[] = "Gujarat\0India\0";
    printf("%d", strlen(name));
    return 0;
}
Check your Answer here...


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

No comments:

Post a Comment