Posts

Showing posts from May, 2022

General Computer Science - 01

What is the Incognito window in Chrome? A google chrome window for browsing privately. It is not possible to see our activity by the people who use our device With private browsing, the following information is not preserved in the browser Browsing history Cookies and site data The data entered in forms But still, the following are visible Websites which we visit Details of ISP (Internet Service Provider) How to Open Incognito Window? Open Chrome Click the three vertical dots in the top right of the browser window Select the New Incognito Window Option (OR) Ctrl + Shift+n HAPPY BROWSING PRIVATELY

Python Tips -05

What is the output of the following Python code snippet? def fun(a):     a.append(100)     print(a) a=[10,20,30] print("Before calling function fun, the value of a=",a) fun(a) print("After calling function fun, the value of a=",a) OUTPUT Before calling function fun, the value of a= [10, 20, 30] [10, 20, 30, 100] After calling function fun, the value of a= [10, 20, 30, 100] Explanation: Here the list a is passed as a parameter to the function namely fun . Since the list is a mutable type, by default it is passed as a reference. So any changes to the parameter a within the function fun will affect the original list a . So the value of the list after function call is [10,20,30,100].

Python Tips - 04

Image
Mutable vs Immutable Objects in PYTHON Every variable in python is an object and there are tw o types of objects in python. They are  Immutable Objects Mutable Objects Immutable Objects Objects that can not be modified after creating int, float, decimal, bool, s tring and tuples are immutable objects in python Mutable Objects Objects that can be modified whenever needed Lists, Dictionaries and Sets are mutable objects in python Examples

C Puzzle 05

Image
Multiply a given number by 2 without using the Multiplication Operator It is possible with the help of the operator <<  << is a shift left operator  << is a binary and bitwise operator The Shift Left operator moves every bit of the operand towards the left and the space created at the right side(LSB) will be filled with a zero. How the shift left operator works? LSB stands for Least Significant bit MSB stands for Most Significant bit Syntax:       Operand = Operand << number of bits to shifted left Examples:   x=x<<1   //1 bit of x to be shifted left   y=y<<2  // 2 bits of y to be shifted left Note:  Performing the shift left operation for the operand by one time is equal to multiplying the operand by two. Program

C Puzzle - 04

Image
 Swap two numbers using a logical operator It is possible to swap two numbers without using a temporary variable and it is possible XOR operator. The truth table of the XOR operator Program #include <stdio.h> int main() {     int a,b;     printf("Enter two numbers\n");     scanf("%d%d",&a,&b);     printf("Before Sawp: a=%d.... b=%d",a,b);     a=a^b;     b=a^b;     a=a^b;     printf("\nAfter Swap: a=%d.... b=%d",a,b);     return 0; } OUTPUT

C Puzzle -03

What is the return value of printf() and scanf() functions in C? scanf() : It returns the number of inputs scanned successfully from keyboard. Example: #include <stdio.h> int main() {    int a,b,c,n;    printf("Enter the values for a, b and c\n");    n=scanf("%d%d%d",&a,&b,&c);  // The variable n receive the return value of scanf    printf("%d",n);    return 0; } Output Enter the values for a, b and c 10 20 30 3 printf() : It returns the number of bytes/characters printed on the screen. Example #include <stdio.h> int main() {    int n,x;    n=10;    x=printf("%d",n);    printf("\nx=%d bytes",x);    return 0; } Output 10 x=2 bytes

Java - Tips - 01

How do you determine the size of primitive data types in JAVA? sizeof() operator in C is used to determine the size of its operand (memory (RAM) required)  In JAVA, there is no sizeof() operator as in C Wrapper classes:   It provides a way to use primitive data typesas objects  Byte, Short, Integer, Long, Float, Double, Character and Boolean are the wrapper classes for the primitive data types byte, short, int, long, float, double, char and boolean respectively Except for the Boolean wrapper class, all other classes have SIZE and BYTES attributes The SIZE attribute determines the size of the data type in bits whereas, the BYTES returns the size of the datatype in bytes. Example: class DetermineSize  {        public static void main(String args[])       {                 System.out.println("size of byte (in bits)="+Byte.SIZE+" bits");        ...