Library Functions

Q1:
Will the program outputs 'AptitudeCrack.com'?
#include<stdio.h>
#include<string.h>

int main()
{
    char str1[] = 'AptitudeCrack.com';
    char str2[20];
    strncpy(str2, str1, 8);
    printf('%s', str2);
    return 0;
}

A Yes

B No

ANS:A - Yes

No. It will print something like 'AptitudeCrack(some garbage values here)' . Because after copying the first 8 characters of source string into target string strncpy() doesn't terminate the target string with a '\0'. So it may print some garbage values along with AptitudeCrack.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.