Friday, December 2, 2016

Identify errors in C program code, correct it and predict the output.

Program-1
#include<stdio.h>
int main()
{
            char str1[10]="ABCDE", str2[  ]=XYZAB;
            printf("String1:%c\n", str1[2+1]);
            printf("String2:%s\n", str2);
            printf("String1 = %d \n", strlength(str1));
            printf("String2 = %d \n", strlen(str2));
            return 0;
}

* * * * * 

Program-2
#include<stdio.h>
void main() {
            int i, max, marks[5]=5,2,3,6,8;
            max = marks[0];
            for(i=0  i<5 i++)
            {
                        if marks[i] < marks[i+1]
                                    max = marks[i+1];
            }
            printf("Max marks = %d \n", max);
}

* * * * * 

Program-3
#include<stdio.h>
void main()
{
            char name[  ] = = "ABCEDFGH";    
            name[0] = 'A';    
            name[2] = 'H';
            name[0] = name[2];
            printf(%c %d, name[0], name[1]);      
}

* * * * * 

No comments:

Post a Comment